問題CheckBoxes
:カスタムに表示される複数のデータをチェックした後でも、選択に関係なくListView
、カスタムに表示されるデータ値の行全体が返されます。確認した後、のステータスはまったく変わらなかったと思いますListView
。では、複数チェックした後、ステータス(true)CheckBox
を設定するにはどうすればよいですか?さらに、送信をクリックしたときにチェックされた位置を取得するにはどうすればよいですか?次に、のクラスを呼び出して、および(ユーザーが入力する)を含む特定のデータ行を取得して、チェック専用の別のカスタムリストに表示するにはどうすればよいですか?CheckBox
CheckBoxes
CheckBoxes
ListView
Button
Model
TextView
EditText
CheckBoxes
概要:チェックボックスがオンになっている値の行の配列を別のページにのみ表示したい。
tests1.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="310dp"
android:layout_x="0dp"
android:layout_y="-4dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="293dp" >
</ListView>
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="113dp"
android:layout_y="346dp"
android:text="Button" />
</AbsoluteLayout>
tests.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="208dp"
android:layout_y="4dp"
android:text="CheckBox" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="11dp"
android:layout_y="15dp"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="22dp"
android:layout_y="49dp"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="42dp"
android:layout_y="89dp"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="35dp"
android:layout_y="123dp"
android:text="TextView" />
<EditText
android:id="@+id/editText1"
android:layout_width="42dp"
android:layout_height="wrap_content"
android:layout_x="147dp"
android:layout_y="13dp"
android:ems="10"
android:inputType="number" />
</AbsoluteLayout>
MultipleSet1.javaクラス:
public class MultipleSet1 extends ListActivity
{
List<Model> list = new ArrayList<Model>();
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.testing1, null);
this.setContentView(viewToLoad);
//final ViewHolder viewHolder = new ViewHolder();
String temp = "Set_A";
String response = null;
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("Name", temp));
try
{
response = CustomHttpClient.executeHttpPost("PhPScripts", postParameters);
}
catch (Exception e)
{
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Fail to connect to server7777777777.", 3).show();
}
int size = 0;
try
{
JSONArray jArray = new JSONArray(response);
size = jArray.length();
for(int i =0; i<size; i++)
{
JSONObject json_data = jArray.getJSONObject(i);
list.add(get(json_data.getString("description"), json_data.getString("price"), false));
}
}
catch (JSONException e)
{
Toast.makeText(getApplicationContext(), "Fail to connect to server7777777777.", 3).show();
}
ArrayAdapter<Model> adapter = new InteractiveListViewAdapter(this, list);
setListAdapter(adapter);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
ListView list = (ListView)findViewById(android.R.id.list);
list = getListView();
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
int size = list.getCount();
String checked = "";
String unchecked = "";
SparseBooleanArray sparseBooleanArray = list.getCheckedItemPositions();
for(int i = 0; i < size; i++)
{
if(sparseBooleanArray.get(i) == true)
{
checked += list.getItemAtPosition(i).toString() + "\n";
}
else if(sparseBooleanArray.get(i) == false)
{
unchecked+= list.getItemAtPosition(i).toString() + "\n";
}
}
Intent intent = new Intent(getApplicationContext(), SingleSet.class);
intent.putExtra("TAG_DESCRIPTION", unchecked);
// Create the view using TabTour's LocalActivityManager
View view1 = bookingTab.group.getLocalActivityManager().startActivity("BookingTab", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
bookingTab.group.replaceView(view1);
}
});
}
private Model get(String name, String score, boolean selected)
{
return new Model (name, score, selected);
}
}
InteractiveListViewAdapter.javaクラス:
public class InteractiveListViewAdapter extends ArrayAdapter<Model>
{
private final List<Model> list;
private final Activity context;
public InteractiveListViewAdapter(Activity context, List<Model> list)
{
super(context, R.layout.testing, list);
this.context = context;
this.list = list;
}
static class ViewHolder
{
protected TextView text;
protected CheckBox checkbox;
protected EditText scores;
}
//@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = null;
if (convertView == null)
{
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.testing, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.textView1);
viewHolder.scores=(EditText) view.findViewById(R.id.editText1);
viewHolder.scores.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before, int count)
{
Model element=(Model)viewHolder.scores.getTag();
element.setScore(s.toString());
}
public void beforeTextChanged(CharSequence s, int start, int count,int after)
{
}
public void afterTextChanged(Editable s)
{
}
});
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.checkBox1);
viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
{
Model element = (Model) viewHolder.checkbox.getTag();
element.setSelected(buttonView.isChecked());
}
});
viewHolder.checkbox.setTag(list.get(position));
viewHolder.scores.setTag(list.get(position));
view.setTag(viewHolder);
}
else
{
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
((ViewHolder) view.getTag()).scores.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
holder.scores.setText(list.get(position).getScore());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
Model.javaクラス:
public class Model
{
private String name;
private String score;
private boolean selected;
public Model(String name, String score, boolean selected)
{
this.name = name;
this.score = score;
this.selected = selected;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public boolean isSelected()
{
return selected;
}
public void setSelected(boolean selected)
{
this.selected = selected;
}
public String getScore()
{
return score;
}
public void setScore(String score)
{
this.score = score;
}
}