gpt4 book ai didi

android - 分析 ListView 标题点击

转载 作者:行者123 更新时间:2023-11-29 18:18:15 25 4
gpt4 key购买 nike

我有 2 个布局 .xml 表单。一种是表头形式,另一种是显示列表。使用标题 View 我可以显示标题。当我尝试单击页眉表单上的按钮时,我无法得到响应。请帮助我这是我的代码。

//To display the Taskname as listview
ListView listView = getListView();
TextView HeaderUnametxt=(TextView) header.findViewById(R.id.UsernameHead);
TextView HeaderCnametxt=(TextView) header.findViewById(R.id.CompanynameHead);
String UName= bundle.getString("UserName");
String CName= bundle.getString("Company");
HeaderUnametxt.setText(UName); //To display the Usename on the header
HeaderCnametxt.setText(CName); //To display the Company Name on the header
listView.addHeaderView(header);
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.tasklist,
R.id.Tasklist, TaskNames));

header.xml 文件为。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:id="@+id/TableRow01"
android:layout_width="fill_parent"
android:background="@color/white"
android:layout_height="wrap_content">
<ImageView android:id="@+id/Imagecompany"
android:layout_width="wrap_content"
android:src="@drawable/company"
android:layout_height="wrap_content">
</ImageView>
<TextView android:background="@color/white"
android:textColor="#0000FF"
android:text="Guest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/CompanynameHead">
</TextView>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:src="@drawable/user"
android:layout_height="wrap_content">
</ImageView>
<TextView android:background="@color/white"
android:textColor="#0000FF"
android:text="Guest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/UsernameHead">
</TextView>
<Button android:text="Log Out"
android:layout_width="60px"
android:layout_height="20px"
android:id="@+id/Logout">
</Button>
</TableRow>
</TableLayout>
</LinearLayout>

最佳答案

试试这个代码...它适用于 ListView 标题按钮点击..

public class ListHeaderActivity extends ListActivity implements
View.OnClickListener {

View header;
ArrayAdapter<String> aR;
ListView lstVw;
String[] str = new String[] { "item1", "item2", "item3", "item4",
"item5", "item6" };

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

lstVw = getListView();
header = getLayoutInflater().inflate(R.layout.header, lstVw, false);
lstVw.addHeaderView(header);
aR = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, str);
lstVw.setAdapter(aR);
View logoutBtn = findViewById(R.id.Logout);
logoutBtn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
Toast.makeText(ListHeaderActivity.this, "it's works.!", 1000).show();
}

}

关于android - 分析 ListView 标题点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6994803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com