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>
android:layout_weight="0.94"去掉這個應該就好了