Android:如何在具有水平方向的线性布局中选取所有视图?

时间:2015-01-18 14:22:01

标签: java android android-layout

我已经制作了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

0 个答案:

没有答案