我有一个列表活动,每行有一个TextView和EditText字段。以前我使用的是simplecursoradapter,但是要解决从EditText获取值并在其他活动中使用的问题。除了回收移动用户输入我试图转移到自定义输入。我已经让它运行但是当它运行时它不会显示我的任何结果。此时它只是在底部显示我的页脚。
//自定义适配器
public class ItemsAdapter extends ArrayAdapter<Model> {
private LayoutInflater mInflater;
private Cursor cursor;
public ItemsAdapter(Context context, int layout, Cursor cursor, String[] from,
int[] to) {
super(context, layout);
this.cursor = cursor;
mInflater = LayoutInflater.from(context);
}
static class ViewHolder {
protected TextView text;
protected EditText edittext;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.edit_row, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.textType);
holder.edittext = (EditText) convertView.findViewById(R.id.editText);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
cursor.moveToPosition(position);
int label_index = cursor.getColumnIndex("userword");
String label = cursor.getString(label_index);
holder.text.setText(label);
return convertView;
}
}
//我的列表活动
public class editview extends ListActivity {
private dbadapter mydbhelper;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mydbhelper = new dbadapter(this);
mydbhelper.open();
View footer = getLayoutInflater().inflate(R.layout.footer_layout, null);
ListView listView = getListView();
listView.addFooterView(footer);
showResults();
}
private void showResults (){
Cursor cursor = mydbhelper.getUserWord();
startManagingCursor(cursor);
String[] from = new String[] {dbadapter.KEY_USERWORD};
int[] to = new int[] {R.id.textType};
ItemsAdapter adapter = new ItemsAdapter(this, R.layout.edit_row, cursor,
from, to);
adapter.notifyDataSetChanged();
this.setListAdapter(adapter);
}
//footer button
public void onClick(View footer){
final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
editClickSound.start();
}
}
//我的光标位于dbadapter类
中 // retrieves all the descriptions for the edittext fields
public Cursor getUserWord()
{
return myDataBase.query(USER_WORD_TABLE, new String[] {
KEY_ID,
KEY_CATEGORY,
KEY_SOURCE, KEY_TITLE, KEY_USERWORD, KEY_QUICK
},
KEY_CATEGORY+ "=" + categories.categoryClick + " AND " + KEY_SOURCE+ "="
+source.sourceClick + " AND " + KEY_TITLE+ "=" + title.titleClick,
null, null, null, KEY_ID);
}
提供有关其工作原理的更多信息。用户将获得一系列Listviews,category-&gt; source-&gt;标题。然后使用EditText将它们带到此活动,我将在其中接受输入并在下一个活动中使用它们。我是自定义游标适配器的新手,因为我是Android的新手并且还在学习,所以我无法理解我所缺少的东西。