找到edittext自定义列表视图

时间:2013-02-05 10:50:21

标签: android android-listview

我正在使用Custom Listview,我在listview_row.xml中使用EditText。我想对更改Edittext Value执行一些操作,但是我如何找到有针对性的edittext并且还希望在该行中显示焦点的输出。我如何找到和编辑文本,并对文本更改执行我的操作,请帮助我,我很困惑,提前感谢....

QuckAcess.java

public class QuickAcess extends Activity {

private ListViewAdapter mAdapter;
   private ArrayList<String> Header;
   private ArrayList<Integer> close;
   private ArrayList<String> From;
   private ArrayList<String> To;
   private ArrayList<String> Value;
   private ListView listView;
   EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quickaccess);


        fillSave();
        mAdapter = new ListViewAdapter(this, Header, From, To, Value, close);
        listView = (ListView) findViewById(R.id.SavedList);
        listView.setAdapter(mAdapter);

        listView.setOnItemClickListener(new OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {



            }
        });    
}
public void fillSave() {
    // TODO Auto-generated method stub


     close = new ArrayList<Integer>();
     close.add(R.drawable.close);
     close.add(R.drawable.close);
     close.add(R.drawable.close);

     Header = new ArrayList<String>();
     Header.add("Temperature" + "  :");
     Header.add("Length");
     Header.add("Mass");

     From = new ArrayList<String>();
     From.add("a" + "  ");
     From.add("b" + "  ");
     From.add("c" + "  ");


     To = new ArrayList<String>();
     To.add("x");
     To.add("y");
     To.add("z");

     Value = new ArrayList<String>();
     Value.add("1");
     Value.add("2");
     Value.add("3");

}

listview_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tvHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header  :  " />

    <TextView
        android:id="@+id/tvfrom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="From   " />

    <ImageView
        android:id="@+id/imgExchange"
        android:layout_width="44dp"
        android:layout_height="36dp"
        android:src="@drawable/swap" />

    <TextView
        android:id="@+id/tvto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="To" />

    <ImageButton
        android:id="@+id/ibclose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/close" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/etValue"
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:inputType="number" >
    </EditText>

    <TextView
        android:id="@+id/tvResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>

ListViewAdapter.java

public class ListViewAdapter extends BaseAdapter {
 private ArrayList<String> Header;
 private ArrayList<Integer> close;
 private ArrayList<String> From;
 private ArrayList<String> To;
 private ArrayList<String> Value;
 private Activity activity;

 public ListViewAdapter(Activity activity,ArrayList<String> Header, ArrayList<String> From,ArrayList<String> To,ArrayList<String> Value,ArrayList<Integer> close) {
 super();
       this.Header = Header;
       this.From = From;
       this.close = close;
       this.activity = activity;
       this.To = To;
       this.Value = Value;


}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 3;
}

@Override
public Object getItem(int paramInt) {
    // TODO Auto-generated method stub
    return close.size();
}

@Override
public long getItemId(int paramInt) {
    // TODO Auto-generated method stub
    return 0;
}
 public static class ViewHolder
   {
       public ImageView imgViewFlag;
       public TextView header,from,to;
       public EditText value;
   }

@Override
public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
    // TODO Auto-generated method stub

    ViewHolder view;
     LayoutInflater inflator = activity.getLayoutInflater();
     if(paramView==null)
       {
           view = new ViewHolder();
           paramView = inflator.inflate(R.layout.listview_row, null);

           view.header = (TextView) paramView.findViewById(R.id.tvHeader);
           view.from = (TextView) paramView.findViewById(R.id.tvfrom);
           view.to = (TextView) paramView.findViewById(R.id.tvto);
           view.value = (EditText) paramView.findViewById(R.id.etValue);
           view.imgViewFlag = (ImageView) paramView.findViewById(R.id.ibclose);
           paramView.setTag(view);
       }
     else
       {
           view = (ViewHolder) paramView.getTag();
       }
     view.header.setText(Header.get(paramInt));
     view.from.setText(From.get(paramInt));
     view.to.setText(To.get(paramInt));
     view.value.setText(Value.get(paramInt));
     view.imgViewFlag.setImageResource(close.get(paramInt));

    return paramView;
}

 }

2 个答案:

答案 0 :(得分:2)

您可以从此处获取索引或行。

@Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long arg3) {

                rowIndex = position;

        }

此外,您还可以在此处将EditTag设置为每个EditText字段

public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
// TODO Auto-generated method stub

ViewHolder view;
 LayoutInflater inflator = activity.getLayoutInflater();
 if(paramView==null)
   {
       view = new ViewHolder();
       paramView = inflator.inflate(R.layout.listview_row, null);

       view.header = (TextView) paramView.findViewById(R.id.tvHeader);
       view.from = (TextView) paramView.findViewById(R.id.tvfrom);
       view.to = (TextView) paramView.findViewById(R.id.tvto);
       view.value = (EditText) paramView.findViewById(R.id.etValue);

       view.value.setTag("myThisEditText");

       view.imgViewFlag = (ImageView) paramView.findViewById(R.id.ibclose);
       paramView.setTag(view);
   }
 else
   {
       view = (ViewHolder) paramView.getTag();
   }
 view.header.setText(Header.get(paramInt));
 view.from.setText(From.get(paramInt));
 view.to.setText(To.get(paramInt));
 view.value.setText(Value.get(paramInt));
 view.imgViewFlag.setImageResource(close.get(paramInt));

return paramView;

}

你可以在onCClickListener上获得这个标签

喜欢

arg1.getTag();

您可以为每个索引进行任何自定义。 希望它会帮助你。

答案 1 :(得分:0)

为列表视图创建一些数组列表。在“AddTextChangeListener”上,您可以搜索列表中的类似项目,并为搜索到的文本加载新的arraylist ...

edittext.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
     //search for the keyword and add the items to a new arraylist
}