package table.periodic;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class Solu extends ListActivity {
String[] formulas={ "Formulas", "Al<sup><small>2</small></sup>(SO<sup><small>4</small></sup>)<sup><small>3</small></sup>"
};
String[] C0s={ "0°C", "31.2"
};
String[] C20s={ "20°C", "36.4"
};
String[] C60s={ "60°C", "59.2"
};
String[] C100s={ "100°C", "89.0"
};
public static final int ONE_ID = Menu.FIRST+1;
public static final int TWO_ID = Menu.FIRST+2;
public static final int THREE_ID = Menu.FIRST+3;
public static final int FOUR_ID = Menu.FIRST+4;
public void OnCreate(Bundle icicle){
super.onCreate(icicle);
setContentView(R.layout.list);
setListAdapter(new IconicAdapter());
}
class IconicAdapter extends ArrayAdapter<Object>{
IconicAdapter(){
super(Solu.this, R.layout.row);
}
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.row, parent, false);
TextView formula=(TextView)row.findViewById(R.id.formula);
TextView C0=(TextView)row.findViewById(R.id.C0);
TextView C20=(TextView)row.findViewById(R.id.C20);
TextView C60=(TextView)row.findViewById(R.id.C60);
TextView C100=(TextView)row.findViewById(R.id.C100);
formula.setText(formulas[position]);
C0.setText(C0s[position]);
C20.setText(C20s[position]);
C60.setText(C60s[position]);
C100.setText(C100s[position]);
return(row);
}
}
public void onListItemClick(ListView parent, View v, int position, long id){
}
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
populateMenu(menu);
}
public boolean onCreateOptionsMenu(Menu menu){
populateMenu(menu);
return(super.onCreateOptionsMenu(menu));
}
public boolean onOptionsItemSelected(MenuItem item){
return(applyMenuChoice(item)||
super.onOptionsItemSelected(item));
}
public boolean onContextItemSelected(MenuItem item){
return(applyMenuChoice(item)||
super.onContextItemSelected(item));
}
private void populateMenu(Menu menu){
menu.add(Menu.NONE, ONE_ID, Menu.NONE, "Help");
menu.add(Menu.NONE, TWO_ID, Menu.NONE, "Home");
menu.add(Menu.NONE, THREE_ID, Menu.NONE, "List");
menu.add(Menu.NONE, FOUR_ID, Menu.NONE, "Table");
}
private boolean applyMenuChoice(MenuItem item){
switch (item.getItemId()){
case ONE_ID:
new AlertDialog.Builder(this)
.setTitle("Help")
.setMessage("Solubilities are given in grams of solute that can be dissolved in 100 g of water at the temperature (°C) indicated.")
.setNeutralButton("Close", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dlg, int sumthin){
}
})
.show();
return(true);
case TWO_ID:
Intent table = new Intent(this, table.class);
startActivity(table);
finish();
return(true);
case THREE_ID:
Intent list = new Intent(this, List.class);
startActivity(list);
finish();
return(true);
case FOUR_ID:
Intent Classic = new Intent(this, Classic.class);
startActivity(Classic);
finish();
return(true);
}
return false;
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
XML列表 XML不加載
XML ROW
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:layout_height="wrap_content" android:textSize="15dp" android:id="@+id/formula" android:text="form" android:layout_width="75dp"></TextView>
<TextView android:textSize="15dp" android:layout_height="wrap_content" android:text="0C" android:id="@+id/C0" android:layout_width="30dp"></TextView>
<TextView android:layout_height="wrap_content" android:textSize="15dp" android:id="@+id/C20" android:text="20C" android:layout_width="35dp"></TextView>
<TextView android:layout_height="wrap_content" android:textSize="15dp" android:id="@+id/C60" android:text="60C" android:layout_width="35dp"></TextView>
<TextView android:layout_height="wrap_content" android:textSize="15dp" android:id="@+id/C100" android:text="60C" android:layout_width="35dp"></TextView>
</LinearLayout>
這就是XML的基本佈局,除了我有大約400多個TextViews – 2011-03-01 23:12:22
也許這是一個將XML放入SO評論的問題,但是您粘貼的XML格式不正確。你在'xmlns:android'後面有一個分號,並且在最後缺少一個' LinearLayout>'結束標記。 – 2011-03-01 23:18:42
@Joshua:建議你縮小你的問題,只包含相關的代碼。對於回答者來說,有太多不相關的代碼需要通過。也考慮將它張貼在PasteBin上。 – 2011-03-01 23:32:00