編輯2:我現在有一個適合我的佈局的設計,我可以滾動,但我的自定義適配器有一個新問題。當我滾動時,我的editText丟失了他們的內容,並被來自其他元素的其他內容所取代。但是當我使用SimpleCursorAdapter時,我沒有任何問題(但我不能使用我的按鈕)。Android ListView無法滾動更多,壞的自定義適配器?
這裏是我的自定義適配器:
private class MySimpleCursorAdapter extends SimpleCursorAdapter
{
ViewHolder vh;
public MySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
cursor = c;
}
public View newView(Context _context, Cursor _cursor, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) _context.getSystemService(_context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.card_stock, parent, false);
vh = new ViewHolder();
vh.idList = (TextView) view.findViewById(R.id.idList);
vh.themeList = (TextView) view.findViewById(R.id.themeList);
vh.questionList = (TextView) view.findViewById(R.id.questionList);
vh.reponseList = (TextView) view.findViewById(R.id.reponseList);
vh.difficulteList = (TextView) view.findViewById(R.id.difficultList);
vh.Supprimer = (Button) view.findViewById(R.id.buttonDelete);
vh.Modifier = (Button) view.findViewById(R.id.buttonModifier);
view.setTag(vh);
return view;
}
public void bindView(View view, Context Context, Cursor cursor) {
vh.idList.setText(cursor.getString(cursor.getColumnIndex(stock._ID)));
vh.themeList.setText(cursor.getString(cursor.getColumnIndex(stock.THEME)));
vh.questionList.setText(cursor.getString(cursor.getColumnIndex(stock.QUESTION)));
vh.reponseList.setText(cursor.getString(cursor.getColumnIndex(stock.REPONSE)));
vh.difficulteList.setText(cursor.getString(cursor.getColumnIndex(stock.DIFFICULTE)));
vh.Supprimer.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
View parentView = (View)v.getParent();
TextView idList = (TextView) parentView.findViewById(R.id.idList);
int id = Integer.parseInt(idList.getText().toString());
deleteOneCard(id);
Toast.makeText(container.getContext(), "Suppression de "+id, Toast.LENGTH_SHORT).show();
}
});
vh.Modifier.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
View parentView = (View)v.getParent();
TextView idList = (TextView) parentView.findViewById(R.id.idList);
TextView themeList = (TextView) parentView.findViewById(R.id.themeList);
themeList.setFocusable(true);
themeList.requestFocus();
/*TextView questionList = (TextView) parentView.findViewById(R.id.questionList);
TextView reponseList = (TextView) parentView.findViewById(R.id.reponseList);
TextView difficulteList = (TextView) parentView.findViewById(R.id.difficultList);*/
int id = Integer.parseInt(idList.getText().toString());
Toast.makeText(container.getContext(), "bouton Modifier pour "+id, Toast.LENGTH_SHORT).show();
}
});
}
}
public class ViewHolder
{
Button Supprimer, Modifier;
TextView idList, themeList, questionList, reponseList, difficulteList;
}
謝謝你們。
你爲什麼使用FrameLayout,然後ListView? –
使用您的列表視圖上方的另一個父佈局 – Anjali
我試圖添加父佈局,更改我的FrameLayout,但它不起作用 –