public class MultiColumnActivity extends Activity implements OnClickListener {
private ArrayList<HashMap<String, String>> list;
Button filterButton;
Context context = this;
ListView lview;
// GridView lview;
final CharSequence[] items = { "Select all", " Date ", " Location to ",
" Client Name ", " Product code ", "Product Description",
"Location from", "Quantity", "Pallets" };
protected ArrayList<CharSequence> selectedInterests = new ArrayList<CharSequence>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
// lview = (GridView) findViewById(R.id.listview);
lview = (ListView) findViewById(R.id.listview);
filterButton = (Button) findViewById(R.id.filterbutton);
filterButton.setOnClickListener(this);
populateList();
listviewAdapter adapter = new listviewAdapter(this, list);
lview.setAdapter(adapter);
int lm = lview.getCount();
System.out.println(lm);
}
private void populateList() {
list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> temp = new HashMap<String, String>();
temp.put(FIRST_COLUMN, "DATE");
temp.put(SECOND_COLUMN, "LOCATION TO");
temp.put(THIRD_COLUMN, "CLIENT NAME");
temp.put(FOURTH_COLUMN, "PRODUCT CODE");
temp.put(FIFTH_COLUMN, "PRODUCT DESCRIPTION");
temp.put(SIXTH_COLUMN, "LOCATION FROM");
temp.put(SEVENTH_COLUMN, "QUANTITY");
temp.put(EIGTH_COLUMN, "PALLETS");
list.add(temp);
HashMap<String, String> temp1 = new HashMap<String, String>();
temp1.put(FIRST_COLUMN, "7 / 2 / 2013");
temp1.put(SECOND_COLUMN, "SW00-000");
temp1.put(THIRD_COLUMN, "Mercury Direct");
temp1.put(FOURTH_COLUMN, "MERCUR-A5WW2013-491-000-000-Loose");
temp1.put(FIFTH_COLUMN, "A5 WORLDWIDE HOLS 13 C");
temp1.put(SIXTH_COLUMN, "Warehouse");
temp1.put(SEVENTH_COLUMN, " 5000");
temp1.put(EIGTH_COLUMN, "1");
list.add(temp1);
HashMap<String, String> temp2 = new HashMap<String, String>();
temp2.put(FIRST_COLUMN, "7 / 2 / 2013");
temp2.put(SECOND_COLUMN, "DAH22A");
temp2.put(THIRD_COLUMN, "Hurtigruten Ltd");
temp2.put(FOURTH_COLUMN, "HURTI-NORWY13-000-000-000-10");
temp2.put(FIFTH_COLUMN, "NORWAY 2013");
temp2.put(SIXTH_COLUMN, "ShrinkWrap");
temp2.put(SEVENTH_COLUMN, " 4000");
temp2.put(EIGTH_COLUMN, "1");
list.add(temp2);
HashMap<String, String> temp3 = new HashMap<String, String>();
temp3.put(FIRST_COLUMN, "7 / 2 / 2013");
temp3.put(SECOND_COLUMN, "DAH22A/02");
temp3.put(THIRD_COLUMN, "Hurtigruten Ltd");
temp3.put(FOURTH_COLUMN, "HURTI-NORWY13-000-000-000-10");
temp3.put(FIFTH_COLUMN, "NORWAY 2013");
temp3.put(SIXTH_COLUMN, "ShrinkWrap");
temp3.put(SEVENTH_COLUMN, " 4000");
temp3.put(EIGTH_COLUMN, "1");
list.add(temp3);
HashMap<String, String> temp4 = new HashMap<String, String>();
temp4.put(FIRST_COLUMN, "7 / 2 / 2013");
temp4.put(SECOND_COLUMN, "DAH22A/02");
temp4.put(THIRD_COLUMN, "Hurtigruten Ltd");
temp4.put(FOURTH_COLUMN, "HURTI-NORWY13-000-000-000-10");
temp4.put(FIFTH_COLUMN, "NORWAY 2013");
temp4.put(SIXTH_COLUMN, "ShrinkWrap");
temp4.put(SEVENTH_COLUMN, " 4000");
temp4.put(EIGTH_COLUMN, "1");
list.add(temp4);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.filterbutton: {
showDialog();
break;
}
default:
break;
}
}
private void showDialog() {
// arraylist to keep the selected items
final ArrayList seletedItems = new ArrayList();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select The Fields");
/*
* boolean[] checkedInterests = new boolean[items.length]; int count =
* items.length;
*
* for (int i = 0; i < count; i++) { checkedInterests[i] =
* selectedInterests .contains(items[i]);
*
* }
*/
builder.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
// indexSelected contains the index of item (of which
// checkbox checked)
@Override
public void onClick(DialogInterface dialog,
int indexSelected, boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the
// selected items
// write your code when user checked the checkbox
seletedItems.add(indexSelected);
selectedInterests.add(items[indexSelected]); // by
// anup
} else if (seletedItems.contains(indexSelected)) {
// Else, if the item is already in the array, remove
// it
// write your code when user Uchecked the checkbox
seletedItems.remove(Integer.valueOf(indexSelected));
}
onChangeSelectedSelection();
}
})
// Set the action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Your code when user clicked on OK
// You can write the code to save the selected item here
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Your code when user clicked on Cancel
}
});
AlertDialog dialog = builder.create();
dialog = builder.create();// AlertDialog dialog; create like this
// outside onClick
dialog.show();
}
protected void onChangeSelectedSelection() {
StringBuilder stringBuilder = new StringBuilder();
for (CharSequence selection : selectedInterests)
stringBuilder.append(selection + ",");
// filterButton.setText(stringBuilder.toString());
String input = selectedInterests.toString();
System.out.println(input);
if (input.contains("Date")) {
Intent intent = new Intent();
intent.setClassName("com.nous.demoexample", "com.nous.demoexample.Dateactvity");
startActivity(intent);
}
}
}
第二类:
public class Dateactvity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.date);
}
}
显示文件代码:
<application android:name=".Dateactvity"></application>
这个错误来了。
09-12 10:58:34.253: E/AndroidRuntime(275): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.nous.demoexample/com.nous.demoexample.Dateactvity}; have you declared this activity in your AndroidManifest.xml?