我们可以在android中添加带有toString()的动态链接按钮吗?

时间:2013-04-08 07:10:23

标签: android

任何建议我如何使用toString()方法添加链接按钮,然后将其添加到listview中。如果我单击按钮然后开始一个新活动。请建议我。 我在修理。

2 个答案:

答案 0 :(得分:1)

那么,您首先要为列表视图创建项目布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >

      <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:text="Show link1"
            />
</LinearLayout>

以下是布局的ListView:

 <ListView
    android:id="@+id/ListView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
  </ListView>

在活动文件

myAdapter adapter = new myAdapter(
            context, R.layout.your_list_item, buttonStrings);
ListView listView = (ListView) findViewById(R.id.ListView1);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // do your logic here with position or id
            Intent myIntent = new Intent(currentActivity.this, nextActivity.class);
            startActivity(myIntent);
        }
    });

MyAdapter中,您可以使用列表项(在您的情况下为按钮命名)

答案 1 :(得分:0)

你可以通过扩展listactivity类来实现这个目标......

只需扩展类并覆盖listitemclick()函数......

并且在......

开始新活动......     Intent i = new Intent(this,yourclass.class);     startActivity(ⅰ);

相关问题