单击listView子项

时间:2014-02-18 23:24:11

标签: java android android-layout listview

我正在尝试单击列表视图中的行,但我的代码仅在我在两行之间按下时才有效

你可以看到这个: http://www.screencast.com/t/2vei8yOQh

注意在rep.xml中我使用表格布局并在其中使用rowTable 我使用这段代码:

  public class LastDaysActivity extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_last_days);
    final Button newFourm = (Button) findViewById(R.id.button1);

    LastDaysAdapter adapter = new LastDaysAdapter(this, getDates(),
            getApplicationContext(), getBusID());

    setListAdapter(adapter);

    newFourm.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(LastDaysActivity.this,
                    TabHostActivity.class);
            startActivity(i);

        }
    });

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    TextView myView = (TextView) v.findViewById(R.id.textView2);
    String text = myView.getText().toString();
    Toast.makeText(this, text + " selected", Toast.LENGTH_LONG).show();
}

编辑xml:

  <?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TableRow
        android:id="@+id/TableRow05"
        android:layout_width="fill_parent"
        android:layout_height="27dp"
        android:layout_marginTop="4dp"
        android:background="@drawable/trans01" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="رقم اللوحة" />

        <TextView
            android:id="@+id/TextView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="200dp"
            android:text="التاريخ"
            android:textSize="12sp" />

    </TableRow>

</TableLayout>

0 个答案:

没有答案