public class MainActivity extends Activity {
AutoCompleteTextView cat;
SimpleAdapter adapter;
ArrayList<HashMap<String, String>> values = new ArrayList<HashMap<String, String>>();
EditText e1,e2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//name();
cat = (AutoCompleteTextView) findViewById(R.id.a_no);
String[] from = { "NAME", "ID" };
int[] to = { R.id.auto_id, R.id.auto_name };
adapter = new SimpleAdapter(MainActivity.this, values, R.layout.row,
from, to);
cat.setAdapter(adapter);
cat.setThreshold(1);
cat.setOnItemClickListener(autoItemSelectedListner);
}
private OnItemClickListener autoItemSelectedListner = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
LinearLayout v1 = (LinearLayout) arg1.getParent();
for (int i = 0; i < v1.getChildCount(); i++) {
EditText e = (EditText) v1.getChildAt(i);
Log.i("Tag Name IS", e.getTag().toString());
}
}
};
}
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/abc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<EditText
android:id="@+id/other"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:tag="cde"
android:hint="Other" >
<requestFocus />
</EditText>
<AutoCompleteTextView
android:id="@+id/a_no"
android:layout_width="wrap_content"
android:layout_height="100dip"
android:ems="10"
android:hint="Account No" >
</AutoCompleteTextView>
</LinearLayout>
鉴于一种观点,我需要获得子视图。我尝试了上面的方法,当我使用EditText
时它工作正常,但是当我处理自动完成时,它无效。我真的被困在这里了。我们非常感谢您的帮助(在此示例中,我需要获取EditText
)的标记值