0

这是我的代码:

adapter= new EditAdapter(getApplicationContext(),sectionTopic);
    setListAdapter(adapter);
    ListView li = this.getListView();
    li.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View myView, int position,
                long arg3) {

            TableLayout view = (TableLayout) myView ;
            TextView name = (TextView) view.findViewById(R.id.name);

            itemName = name.getText().toString();



            Intent intent= new Intent(EditActivity.this, SectionDetailsActivity.class);
            intent.putExtra("title", itemName);

            startActivityForResult(intent,1);

        }
    });

编辑适配器:

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View vowView = inflater.inflate(R.layout.activity_edit, parent, false);

    if (position%2==1){
        vowView.setBackgroundColor(Color.rgb(170, 218, 203));
    }
    else{
        vowView.setBackgroundColor(Color.rgb(147, 213, 212));
    }

    TextView name = (TextView) vowView.findViewById(R.id.name);
    TextView budget = (TextView) vowView.findViewById(R.id.budget);
    TextView expense = (TextView) vowView.findViewById(R.id.expense);
    ImageView pic = (ImageView) vowView.findViewById(R.id.pic);

    budget.setText(String.format("%.2f",arrayList.get(position).getBudget()));
    name.setText(arrayList.get(position).getName());
    expense.setText(String.format("%.2f",arrayList.get(position).getMaking()));

    AsyncDownloadImage image = new AsyncDownloadImage(pic);
    image.execute(arrayList.get(position).getPic());


    return vowView;
}

我有一个 tableRow 的 ListView,当您单击一行时,您将移动到另一个屏幕。除此之外,我希望当我按下某个列(在文本视图-“addBtn”上)时,它会移动到另一个屏幕。

如何点击具体?

这是我的列表视图表:

<TableRow 
    android:id="@+id/table"
    android:baselineAligned="false"
    android:background="#e0eee0" >

    <TextView
        android:id="@+id/addBtn"
        android:layout_width="30dp"
        android:layout_height="40dp"
        android:layout_margin="0.5dp"
        android:background="@drawable/plus"
        android:gravity="center"
        android:lines="2"
        android:textColor="@color/Black"

         />

    <TextView
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:id="@+id/expense"
        android:layout_margin="0.5dp"
        android:background="#e6e6fa"
        android:gravity="center"
        android:text="900"
        android:textColor="@color/Black"
        android:lines="2"
         />

    <TextView
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:id="@+id/budget"
        android:layout_margin="0.5dp"
        android:background="#ffe4e1"
        android:gravity="center"
        android:text="1000"
        android:lines="2"
        android:textColor="@color/Black" />

    <TextView
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:id="@+id/name"
        android:layout_margin="0.5dp"
        android:background="#e0eee0"
        android:gravity="center"
        android:text="מזון"
        android:textColor="@color/Black"
        android:lines="2" />
</TableRow>
4

2 回答 2

0

为了能够通过单击View行内的某些内容来移动到其他活动,您需要设置OnClickListener您的视图内部getView方法。

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) mContext
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View vowView = inflater.inflate(R.layout.activity_edit, parent, false);

    if (position%2==1){
        vowView.setBackgroundColor(Color.rgb(170, 218, 203));
    }
    else{
        vowView.setBackgroundColor(Color.rgb(147, 213, 212));
    }

    TextView name = (TextView) vowView.findViewById(R.id.name);
    TextView budget = (TextView) vowView.findViewById(R.id.budget);
    TextView expense = (TextView) vowView.findViewById(R.id.expense);
    ImageView pic = (ImageView) vowView.findViewById(R.id.pic);

    // ... here ->
    TextView button = (TextView) vowView.findViewById(R.id.addBtn);
    button.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // open here other activity
        }
    });
    // <- ....

    budget.setText(String.format("%.2f",arrayList.get(position).getBudget()));
    name.setText(arrayList.get(position).getName());
    expense.setText(String.format("%.2f",arrayList.get(position).getMaking()));

    AsyncDownloadImage image = new AsyncDownloadImage(pic);
    image.execute(arrayList.get(position).getPic());

    return vowView;
}
于 2013-09-03T13:43:56.837 回答
0

看看这个博客,它是关于列表视图项目中的可点击区域的,这可能会有所帮助。

于 2013-09-03T13:55:26.700 回答