我想獲取密碼描述文本輸入來填充我的應用程序的數組視圖。Arraylist無法應用
不幸的是,我同時部分(cursor.movetoNext())說,我的字符串不能被應用到ArrayList中。我試圖確定要更改我的updateList方法以適應我的密碼項目。
這是我的更新列表方法。
private void updateList(){
ArrayList<String> tasklist = new ArrayList<>();
SQLiteDatabase db = mHelper.getReadableDatabase();
Cursor cursor = db.query(PasswordContract.PasswordEntry.TABLE, new String[]{PasswordContract.PasswordEntry._ID, PasswordContract.PasswordEntry.COL_PASSWORD, PasswordContract.PasswordEntry.COL_PASS_DESC},
null, null, null, null, null);
while (cursor.moveToNext()){
String password = cursor.getString(cursor.getColumnIndex(PasswordContract.PasswordEntry.COL_PASSWORD));
String description = cursor.getString(cursor.getColumnIndex(PasswordContract.PasswordEntry.COL_PASS_DESC));
tasklist.add(new PasswordItem(password, description));
if (mAdapter == null){
mAdapter = new ArrayAdapter<>(this,
R.layout.item_password,
R.id.password,
R.id.password_description,
tasklist);
mPasswordListView.setAdapter(mAdapter);
}else{
mAdapter.clear();
mAdapter.addAll(String.valueOf(tasklist));
mAdapter.notifyDataSetChanged();
}
cursor.close();
db.close();
我想弄清楚如何將我的customadapter連接到我的更新列表方法。
public class CustomAdapter extends ArrayAdapter<String>{
private Context mContext;
private List<String> mStringList;
public CustomAdapter(Context context, List<String> mStringList) {
super(context, R.layout.item_password);
this.mContext = context;
this.mStringList = new ArrayList<>();
this.mStringList = mStringList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_password, parent, false);
TextView your_first_text_view = (TextView) convertView.findViewById(R.id.password);
TextView your_second_text_view = (TextView) convertView.findViewById(R.id.password_description);
your_first_text_view.setText(mStringList.get(position));
your_second_text_view.setText(mStringList.get(position));
return convertView;
}
Pavneet,幾乎在那裏。我在updatelist方法中添加了if和else語句。我已更新我的帖子以顯示他們。 arrayadapter說明不能推斷參數。你知道這是什麼原因嗎? –
它仍然說arrayadapter不能應用。 –
等我拿到了,讓我更新 –