我是android的新手..
我面临着列表视图的问题..
如何实现列表视图的tittle?帮帮我......
我试试这个..
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); viewList = Nexttopic.this.getLayoutInflater().inflate(R.layout.activity_nexttopic, null); dialogMarketList = new Dialog(Nexttopic.this); dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE); dialogMarketList.setTitle("TOPICS"); dialogMarketList.setContentView(viewList); dialogMarketList.show(); lvForDialog = (ListView) viewList.findViewById(R.id.List_view); lvForDialog.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); ArrayAdapter<String> adapter = (new ArrayAdapter<String>(Nexttopic.this, R.layout.row_topic, R.id.child_row,tnamelist)); lvForDialog.setAdapter(adapter);
它不起作用..
答案 0 :(得分:2)
删除它:
dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
使用这种方式:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
viewList = getLayoutInflater().inflate(R.layout.activity_main_, null);
dialogMarketList = new Dialog(MainActivity.this);
dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogMarketList.setTitle("TOPICS");
dialogMarketList.setContentView(viewList);
dialogMarketList.show();
ListView lvForDialog = (ListView) viewList.findViewById(R.id.listView1);
header = inflater.inflate(R.layout.header, null);
lvForDialog.addHeaderView(header);
lvForDialog.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
ArrayAdapter<String> adapter = (new ArrayAdapter<String>(
MainActivity.this, android.R.layout.simple_list_item_1, a));
lvForDialog.setAdapter(adapter);
header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="my title"
android:textAppearance="?android:attr/textAppearanceLarge" />
第二次编辑:
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("my Title");
builder.setIcon(getResources().getDrawable(R.drawable.ic_launcher));
builder.setAdapter(new ArrayAdapter<String>(MainActivity.this,
R.layout.row, R.id.child_row, items),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
答案 1 :(得分:0)
代码中的以下命令会禁用对话框中的标题:
dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
如果删除它,您应该看到带有标题的对话框。
答案 2 :(得分:0)
答案 3 :(得分:0)
尝试在headerView
中添加listView
,您需要先致电setAdapter()
docs说什么/
public void addHeaderView (View v)
*添加固定视图以显示在列表顶部。如果多次调用addHeaderView,视图将按添加顺序显示。使用此调用添加的视图可以在需要时获得焦点。 注意:在调用setAdapter之前调用此方法。这样,ListView可以将提供的光标包装起来,也可以考虑页眉和页脚视图。