package com.example.myadapter;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity {
ListView name,tech;
Button start;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(ListView) findViewById(R.id.name);
tech=(ListView) findViewById(R.id.tech);
start=(Button) findViewById(R.id.button1);
final String[] list1={"河南","福建","广东","浙江","北京","台湾"};
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.item,list1);
name.setAdapter(adapter);
name.setOnItemClickListener(<span style="color:#FF0000;">new AdapterView.OnItemClickListener() </span>{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
list1[position], Toast.LENGTH_SHORT).show();
}
});
String[] list2={"Java","C++","HTML","CSS","JavaScript","Struct2"};
ArrayAdapter<String> adapter1=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,list2);
tech.setAdapter(adapter1);
tech.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
start.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(getApplicationContext(), myListActivity.class);
startActivity(intent);
}
});
}
}
ListView
最新推荐文章于 2018-06-12 17:03:35 发布