画像とラジオボタンを使用してカスタムリストビューを使用しています。次に、これらのラジオ ボタンをグループ化します。これが私xml
のJavaクラスプログラムです。
<?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" >
<ImageView
android:id="@+id/image"
android:layout_width="55dip"
android:layout_height="55dip"
android:scaleType="centerCrop"
android:src="@drawable/stub" />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="208dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="0.56"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private String[] conditions;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, String[] d, String[] c) {
activity = a;
data=d;
conditions=c;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text1);
ImageView image=(ImageView)vi.findViewById(R.id.image);
text.setText(conditions[position]);
imageLoader.DisplayImage(data[position], image);
return vi;
}
そしてJavaの2番目のクラス..
public class WeatherCondition extends Activity {
ListView list1;
LazyAdapter adapter;
ImageButton done,cancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weather_conditions);
done=(ImageButton)findViewById(R.id.imageButton1);
done.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(WeatherCondition.this, AddWeatherAlarm.class);
startActivity(intent);
}
});
cancel=(ImageButton)findViewById(R.id.imageButton2);
cancel.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(WeatherCondition.this, AddWeatherAlarm.class);
startActivity(intent);
}
});
list1=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(this, mStrings,conditions);
list1.setAdapter(adapter);
list1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(WeatherCondition.this, ""+conditions[arg2],Toast.LENGTH_SHORT).show();
}
});
}
String conditions[]={ "Clear/Sunny","Partly Cloudy","Cloudy","Overcast","Mist","Patchy rain nearby","Patchy snow nearby","Patchy sleet nearby","Patchy freezing drizzle nearby","Thundery outbreaks in nearby","Blowing snow","Blizzard","Fog","Freezing fog","Patchy light drizzle","Light drizzle","Freezing drizzle","Heavy freezing drizzle","Patchy light rain","Light rain","Moderate rain at times","Moderate rain","Heavy rain at times","Heavy rain","Light freezing rain","Moderate or Heavy freezing rain","Light sleet","Moderate or heavy sleet","Patchy light snow","Light snow","Patchy moderate snow","Moderate snow","Patchy heavy snow","Heavy snow","Ice pellets","Light rain shower","Moderate or heavy rain shower","Torrential rain shower","Light sleet showers","Moderate or heavy sleet showers","Light snow showers","Moderate or heavy snow showers","Light showers of ice pellets","Moderate or heavy showers of ice pellets","Patchy light rain in area with thunder","Moderate or heavy rain in area with thunder","Patchy light snow in area with thunder","Moderate or heavy snow in area with thunder"};
}
}