gpt4 book ai didi

android - 找到 edittext 自定义 ListView

转载 作者:行者123 更新时间:2023-11-29 21:49:49 24 4
gpt4 key购买 nike

我正在使用 Custom Listview,我正在使用 listview_row.xml 中的 EditText。我想对更改 Edittext 值执行一些操作,但是我如何找到聚焦的 edittext 并且还想在聚焦的那一行中显示输出。我如何找到 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;
}

}

最佳答案

您可以从这里获取索引或行。

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

rowIndex = position;

}

您还可以在此处为每个 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();

并且您可以对每个索引进行任何自定义。希望对您有所帮助。

关于android - 找到 edittext 自定义 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14705756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com