layout中listview占据了整个界面,其余控件全部隐藏,xml文件怎么改都没用,只要listview有数据,就看不到添加的BUTTON或者EXITVIEW了。
布局文件:
<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/btshanchu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="删除"
/>
<ListView
android:id="@+id/Lziliao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btshanchu"/>
java文件:
package com.example.huclass;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
public class GuanliActivity extends Activity {
private ListView listView;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
listView = new ListView(this);
//android.R.layout.simple_list_item_1是系统定义好的布局文件只显示一行文字
listView.setAdapter((ListAdapter) new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData()));
setContentView(listView);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, getData()));
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);}
private List getData(){
List<String> data = new ArrayList<String>();
data.add("【计算机网络】数据链路层");
data.add("【计算机网络】应用层");
data.add("【信息论】香农定理");
data.add("【概率论】总结");
return data;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.guanli, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}