데이터베이스에서 사용자 지정 ListView로 데이터를 채우는 데 도움이 필요합니다. 내 자신의 사용자 지정 XML 파일을 사용하여 데이터베이스에서 데이터를 표시 할 수있었습니다. 지금 가지고있는 문제는 세 개의 열이 각각의 TextView에 반환된다는 것입니다. - 각 열은 해당 TextView로 파싱되지 않습니다. 나는 내가 필요로하는 것을 구술 적으로 설명하려고 시도 할 것이다. 미안하지만, 여분의 지언을 원한다. 불필요한 대답을보고있다. &이 게시물에 대한 코멘트이다. 어떤 회원은 코드 &을보고 승/대부분의 Q는 따라 가기 힘듭니다.) 시간을내어 도와 주셔서 감사합니다. 나는 안드로이드데이터베이스에서 사용자 지정 목록보기
list_view.xml는 RealitiveLayout/승의 LinearLayout을 가지고자바 &에 나는 그런에 새로운 답을 이해하고 있지 않다 경우 나는 시간에 앞서 사과 승/(맞춤 제목 표시 줄에 대한) 그와의 ListView w/a "listItems"의 자원 ID. ListView (R.id.listItems)는 LinearLayout에서 사용되며 list_item.xml을 사용합니다. list_item.xml에는 자원 ID가 "acItems"인 RelativeLayout이 있습니다. 여기에는 "label", "listTitle", & "caption"의 리소스 ID가있는 세 개의 TextView가 있습니다. 각각은 자신의 스타일을 가지고 있습니다. 장치 SD 카드에있는 데이터베이스 (xxx.db)를 쿼리해야합니다. 이 데이터베이스에있는 테이블은 "_id", "label", "title"& "goto"열을 포함하는 'AC_list'로 이름이 지정됩니다. 이 열은 ListView (R.id.listItems) 내에서 해당 TextView (레이블 n2 "label", 제목 n2 "listTitle", & 설명 n2 "캡션")로 전달되어야합니다. 각 DB 행에 대한 자신의 스타일링. 아래를 참조
list_view.xml을 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="30dip"
android:padding="4dip"
android:background="@drawable/gradient" >
<ImageButton
android:id="@+id/homeBtn"
android:src="@drawable/ic_menu_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@null" />
<TextView
android:id="@+id/titleBarTitle"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp" />
<ImageButton
android:id="@+id/toolBtn"
android:src="@drawable/ic_menu_list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@null" />
</RelativeLayout>
<ListView
android:id="@+id/listItems"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
list_item.xml :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/acItem"
style="@style/listItem" >
<TextView
android:id="@+id/label"
style="@style/listAcronym" />
<TextView
android:id="@+id/listTitle"
style="@style/listTitle" />
<TextView
android:id="@+id/caption"
style="@style/listDiscription"/>
<ImageView
style="@style/listNextIcon" />
</RelativeLayout>
내 어댑터 (AC_Adapter.java) :
public class AC_Adapter extends ArrayAdapter<String> {
static List<String> Title = new ArrayList<String>();
static List<String> Label = new ArrayList<String>();
static List<String> Description = new ArrayList<String>();
Context myContext;
public AC_Adapter(Context context, int resource, List<String> aTitle,
List<String> aLabel, List<String> aDescription) {
super(context, resource, aTitle);
myContext = context;
Title = aTitle;
Label = aLabel;
Description = aDescription;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
}
TextView tv_label = (TextView) v.findViewById(R.id.label);
TextView tv_title = (TextView) v.findViewById(R.id.listTitle);
TextView tv_decription = (TextView) v.findViewById(R.id.caption);
if (tv_label != null) {
tv_label.setText(Label.get(position));
}
if (tv_title != null) {
tv_title.setText(Title.get(position));
}
if (tv_decription != null) {
tv_decription.setText(Description.get(position));
}
return v;
}
}
그리고 내 활동 (List_AC.java) :
public class List_AC extends ListActivity {
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String extStorageDirectory;
private ArrayList<String> results = new ArrayList<String>();
/**
* -- Called when the activity is first created
* ===================================================================
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
//setContentView(R.layout.list_view2);
openAndQueryDatabase();
displayResultList();
}
/**
* -- Connect to the AC_Adapter
* ===================================================================
**/
private void displayResultList() {
AC_Adapter adapter = new AC_Adapter(getApplicationContext(),
R.layout.list_item, results, results, results);
setListAdapter(adapter);
}
/**
* -- Open and Query the Database
* ====================================================================
**/
private void openAndQueryDatabase() {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File dbfile = new File(extStorageDirectory
+ "/XXX/XXX/dB/XXX.db");
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
Log.i("tag", "db opened");
try {
Cursor c = db.rawQuery(
"SELECT label, title, discription, goto FROM AC_list", null);
if (c != null) {
if (c.moveToFirst()) {
do {
String i1 = c.getString(c.getColumnIndex("label"));
String i2 = c.getString(c.getColumnIndex("title"));
String i3 = c.getString(c.getColumnIndex("discription"));
results.add(i1);
} while (c.moveToNext());
}
}
} finally {
if (db != null)
Log.i("tag", "db closed");
db.close();
}
} else if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_UNMOUNTED)) {
Log.i("tag", "SDCard is NOT writable/mounted");
Alerts.sdCardMissing(this);
}
}
}