/* Code java : */
package com.example.membuatseletionwidget;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.ListActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class SelectionWidgetActivity extends ListActivity {
TextView seleksi;
String[] pilihan = { "Maintboard", "Memory", "HDD", "Monitor",
"Processor", "Slot
PCI", "Power Supply", "Sound Card",
"Modem", "Driver", "Support" };
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selection_widget);
setListAdapter(new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, pilihan));
seleksi = (TextView)
findViewById(R.id.yangDipilih); } public void
onListItemClick(ListView parent, View v, int position, long id) { seleksi.setText(pilihan[position]);
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the
menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.selection_widget, 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);
}
}
/* Xml Code: */
<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/yangDipilih"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffaa88"
android:layout_gravity="center"
android:layout_weight="1"
android:drawSelectorOnTop="false"
/>
</LinearLayout>
0 comments:
Post a Comment