滚动列表视图时,文本框的数据消失

时间:2013-08-31 19:21:26

标签: android listview android-listview android-edittext

我有一个ListView,每个项目都有一个edittext,当我在editTexts中写一些内容并滚动listview时,我输入的数据将消失。我已经阅读了this主题,但实际上我没有得到我的编码方式!任何人都可以帮助我吗?

java代码:

public class ListView extends ListActivity {
    /** Called when the activity is first created. */
    private TextView selection;
    private static final String[] items = {"مخصوص", "مخلوط", "یونانی", "قارچ و گوشت", "پپرونی", "مرغ و قارچ", "سبزیجات", "دریایی"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view);

        setListAdapter(new IconicAdapter());
        selection = (TextView)findViewById(R.id.selection);

    }
    private String getModel(int position){
        return(((IconicAdapter)getListAdapter()).getItem(position));
    }

    public void onListItemClick(ListView parent, View v, int position, long id){
        selection.setText(items[position]);
    }



 //=====================
 //New Class Starts Here
 //=====================
    class IconicAdapter extends ArrayAdapter<String> {

        public IconicAdapter() {
            super(ListView.this, R.layout.row, items);
        }

        public View getView(int position, View convertView, ViewGroup parent){
            LayoutInflater inflater = getLayoutInflater();
            final View row = inflater.inflate(R.layout.row, parent, false);



            TextView label = (TextView)row.findViewById(R.id.label);
            label.setText(items[position]);

            ImageView icon = (ImageView)row.findViewById(R.id.pic);


            if(getModel(position).contentEquals("مخصوص")){
                icon.setImageResource(R.drawable.download);
            }
            else if (getModel(position).contains("دریایی")){
                icon.setImageResource(R.drawable.drink);
            }
            else if (getModel(position).contains("سبزیجات")){
                icon.setImageResource(R.drawable.french);
            }
            else if (getModel(position).contains("مرغ و قارچ")){
                icon.setImageResource(R.drawable.frenchfrise);
            }
            else if (getModel(position).contains("پپرونی")){
                icon.setImageResource(R.drawable.sandwich);
            }
            else if (getModel(position).contains("قارچ و گوشت")){
                icon.setImageResource(R.drawable.ic_launcher);
            }
            else if (getModel(position).contains("یونانی")){
                icon.setImageResource(R.drawable.sandwich);
            }
            else if (getModel(position).contains("مخلوط")){
                icon.setImageResource(R.drawable.sandwich);
            }
            else if (getModel(position).contains("مخصوص")){
            icon.setImageResource(R.drawable.sandwich);
            }


            return(row);
        }

    }
}

0 个答案:

没有答案