我已经制作了Linear Layout
,每次按下TextView
中的某个键时,我都会动态添加视图(仅EditText
),这会进一步调用查询方法来更新LinearLayout
1}}并用视图对其进行充气。
activity_main.xml中:
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
</LinearLayout>
MainActivity.java:
private void autoCompleteText() {
int i = 0;
current_search = editText1.getText().toString();
String val = "";
// arr is an array of strings
for (String str : arr) {
if (str.startsWith(current_search)) {
final TextView t = new TextView(_context);
t.setId(i++);
t.setLayoutParams(p);
t.setBackgroundResource(color.holo_blue_bright);
t.setText(str);
linLayout.addView(t);
t.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(_context, String.valueOf(t.getId())+ " "+ t.getX(),
Toast.LENGTH_SHORT).show();
}
});
}
}
}
我不希望单TextView
出现在LinearLayout
。