2 growtech growtech 于 2013.06.15 18:03 提问

从集合中查数据到ListView

public class Select extends Activity {
Button btnjin;
EditText Sel;
ListView lSel;
ArrayAdapter arrayAdapter=null;
List list=new ArrayList();
List list2=new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lSel=(ListView)findViewById(R.id.lvinaccountinfo);
Sel=(EditText)findViewById(R.id.editText1);
btnjin=(Button)findViewById(R.id.button1);
setContentView(R.layout.text4);
ExitApplication.getInstance().addActivity(this);
list.add("aaaa");
list.add("bbbb");
list.add("cccc");
list.add("dddd");
arrayAdapter=new ArrayAdapter(Select.this,android.R.layout.simple_list_item_1,list);
lSel.setAdapter(arrayAdapter);
btnjin.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
for(String sel: list){
if(sel.equals(Sel)){
list2.add(sel);
}
}
arrayAdapter=new ArrayAdapter(Select.this,android.R.layout.simple_list_item_1,list2);
lSel.setAdapter(arrayAdapter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这个界面出错

xml中是这样写的
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".RelativeLayout" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="查询" />
<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/button1"
    android:layout_toLeftOf="@+id/button1"
    android:ems="10"
    android:inputType="number" />
<LinearLayout android:id="@+id/linearLayout2"
     android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_weight="0.94"        
    >
<ListView android:id="@+id/lvinaccountinfo"
         android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:scrollbarAlwaysDrawVerticalTrack="true"
    />
</LinearLayout>

1个回答

cj6585256
cj6585256   2013.06.18 10:45
已采纳

android:layout_weight="0.94"去掉这个应该就好了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!