edit2:我现在有一个合适的布局设计,我可以滚动,但我的自定义适配器有一个新问题。当我滚动时,我的edittext会丢失它们的内容,并被来自其他元素的其他内容替换。但是当我使用simplecursoradapter时,我没有任何问题(但是我不能使用我的按钮)。
这是我的自定义适配器:
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;
}
谢谢你们。
4条答案
按热度按时间ryhaxcpt1#
我的问题解决了!在扩展SimpleCorsorAdapter的内部类中,在bindview函数中,我必须再次初始化edittext!!这样地:
zzzyeukh2#
或者
使用linearlayout并更改
ListView
高度至0dp
并添加weight=1
```<LinearLayout
........
android:orientation="vertical">
yb3bgrhw3#
尝试将所有可滚动的内容添加到单个relativelayout中,并将此内容添加到scrollview中。
或
第一个示例中的relativelayout是必需的,因为scrollview元素只接受一个子元素。
hgncfbus4#
设置
ListView
高度至match_parent
. 因此,它将占据父对象的整个区域View
.