标签:string parent ted 代码 dialog [] match raw mat
一、alertdialog
java:
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("This is Dialog");
dialog.setMessage("Something important.");
dialog.setCancelable(false);
dialog.setPositiveButton("OK",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
}
});
dialog.setNegativeButton("Cancel",new DialogInterface.OnclickListener(){
public void onClick(DialogInterface diailog,int which){
}
});
dialog.show();
kotlin:
fun alert(v:View?){
val dialog1=AlertDialog.Builder(this)
dialog1.setTitle("This is Dialog")
dialog1.setMessage("Something important.")
dialog1.setCancelable(false)
dialog1.create().show()
}
二、listview
java:
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
private String[] data={"Apple","Banana","Orange","Watermelon","Pear","Grape","Pineapple",
"Strawberry","Cherry","Mango","Apple","Banana","Orange","Watermelon",
"Pear","Grape","Pineapple","Strawberry","Cherry","Mango"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(
MainActivity.this,R.layout.abc_action_menu_item_layout,data);
ListView listView=(ListView)findViewById(R.id.list_view);
listView.setAdapter(adapter);
}
kotlin:
private val data = arrayOf("Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple",
"Strawberry", "Cherry", "Mango", "Apple", "Banana", "Orange", "Watermelon",
"Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango")
override fun onCreate(savedInstanceState: Bundle?) {
val adapter = ArrayAdapter(
this@MainActivity, R.layout.abc_action_menu_item_layout, data)
listView.adapter = adapter
}
标签:string parent ted 代码 dialog [] match raw mat
原文地址:http://www.cnblogs.com/hunter0541/p/7264235.html