我正在使用自定义 Listview,并且在 listview_row.xml 中使用 EditText。我想对更改 Edittext 值执行一些操作,但是我如何找到焦点编辑文本,并且还想在焦点所在的行中显示输出。我如何找到和编辑文本并对文本更改执行我的操作,请帮助我,我很困惑,在此先感谢....
QuckAccess.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;
}
}