Я создал Адаптер для заполнения моего пользовательского списка, и при запуске на эмуляторе действие остается пустым. Пожалуйста, помогите. Я уверен, что что-то упустил, потому что я новичок в Java и Android. Некоторые фрагменты кода для исправления и указатели будут оценены. Thnx!
Моя активность:
public class List_AC3 extends ListActivity {
/**
* -- 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);
displayResultList();
}
private void displayResultList() {
Cursor databaseCursor = null;
DomainAdapter databaseListAdapter = new DomainAdapter(this, R.layout.list_item, databaseCursor,
new String[] {"label", "title", "description"},
new int[] { R.id.label, R.id.listTitle, R.id.caption });
databaseListAdapter.notifyDataSetChanged();
setListAdapter(databaseListAdapter);
}
}
Мой адаптер:
public class DomainAdapter extends SimpleCursorAdapter{
private LayoutInflater mInflater;
String extStorageDirectory;
public DomainAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.label);
holder.text2 = (TextView) convertView.findViewById(R.id.listTitle);
holder.text3 = (TextView) convertView.findViewById(R.id.caption);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File dbfile = new File(extStorageDirectory+ "/Aero-Technologies/flyDroid/dB/flyDroid.db");
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
Cursor data = db.rawQuery("SELECT * FROM AC_list", null);
data.moveToPosition(position);
int label_index = data.getColumnIndex("label");
String label = data.getString(label_index);
int title_index = data.getColumnIndex("title");
String title = data.getString(title_index);
int description_index = data.getColumnIndex("description");
String description = data.getString(description_index);
holder.text1.setText(label);
holder.text2.setText(title);
holder.text3.setText(description);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
TextView text3;
}
}
The list_view2.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/android:list"
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>