嗨,我正在制作 android 应用程序。我在我的应用程序中使用 json 解析。首先这是我的 json 响应
{
"Data": {
"headerText": "Revolution",
"productStartingPrice": "$38.78",
"sizeList": [
{
"textUpper": "Revolution for (Pink)",
"textLower": "$38.78",
"packList": [
{
"textUpper": "3 DOSES",
"textLower": "$38.78",
}
{
"textUpper": "6 DOSES",
"textLower": "$71.60",
}
]
},
{
"textUpper": "Revolution for (Blue)",
"textLower": "$46.92",
"packList": [
{
"textUpper": "3 DOSES",
"textLower": "$46.92",
}
{
"textUpper": "6 DOSES",
"textLower": "$79.56",
}
{
"textUpper": "12 DOSES",
"textLower": "$137.27",
}
]
}
]
},
"Status": 1,
"Message": "",
"UserMessage": ""
}
现在我正在使用自定义警报对话框来加载 sizelist 数组和另一个用于 packlist 数组的 dailog。现在我想要的是当用户从 sizelist 中选择(粉红色)然后在第二个 dailog 中我想从 packlist 中显示 3 剂和 6 剂,当用户选择(蓝色)时我想显示 3 剂、6 剂、12 剂。现在我只得到最后两项(蓝色)6 剂,12 剂。谁能帮我解决这个问题?
private void showDialog(){
dialogf = new Dialog(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_main, null);
ListView lv = (ListView) view.findViewById(R.id.custom_list);
Button close_btn = (Button) view.findViewById(R.id.close_btn_sizelist);
sizeadapter = new CustomListAdapterSize(getActivity(), sizelists);
lv.setAdapter(sizeadapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
dialogf.setContentView(view);
dialogf.show();
close_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogf.dismiss();
}
});
}
private void showDialogpacks(){
dialogfpacks = new Dialog(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_main_packs, null);
ListView lv = (ListView) view.findViewById(R.id.custom_list_packs);
Button close_btn = (Button) view.findViewById(R.id.close_btn_packlist);
adapterpacks = new CustomListAdaptertwo(getActivity(), sizelists);
lv.setAdapter(adapterpacks);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
dialogfpacks.setContentView(view);
dialogfpacks.show();
}
public class CustomListAdapterSize extends BaseAdapter {
private Context context;
private LayoutInflater inflater;
private List<ProductLandingSizeListModel> adaptersizelist;
private CheckBox selected =null;
private RadioButton mSelectedRB;
public CustomListAdapterSize(Context context,List<ProductLandingSizeListModel> movieItems) {
this.context = context;
this.adaptersizelist=movieItems;
}
@Override
public int getCount() {
return adaptersizelist.size();
}
@Override
public Object getItem(int position) {
return adaptersizelist.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.listitem_productsizes, null);
holder.txtproname = (TextView) convertView.findViewById(R.id.txtproductsizenames);
holder.txtproprice = (TextView) convertView.findViewById(R.id.txtproductsizeprice);
holder.radioBtn = (CheckBox)convertView.findViewById(R.id.productsize_radio);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
final ProductLandingSizeListModel m = adaptersizelist.get(position);
holder.txtproname.setText(m.getSizeList_textUpper());
holder.txtproprice.setText(m.getSizeList_textLower());
if (position == mSelectedPosition ) {
if (selected == null) {
holder.radioBtn.setChecked(true);
selected = holder.radioBtn;
}
}
if (position == mSelectedPosition )
holder.radioBtn.setChecked(true);
else
holder.radioBtn.setChecked(false);
holder.radioBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (selected != null) {
selected.setChecked(false);
}
mSelectedPosition =position;
if(mSelectedPositionpack!=0)
{
mSelectedPositionpack=0;
}
holder.radioBtn.setChecked(true);
selected = holder.radioBtn;
notifyDataSetChanged();
dialogf.dismiss();
showDialogpacks();
}
});
return convertView;
}
class ViewHolder{
TextView txtproname,txtproprice;
public CheckBox radioBtn;
}
}
public class CustomListAdaptertwo extends BaseAdapter {
private CheckBox selected =null;
private Context context;
private LayoutInflater inflater;
private List<ProductLandingSizeListModel> adaptersizelist;
public CustomListAdaptertwo(Context context,List<ProductLandingSizeListModel> adaptersizelist) {
this.context = context;
this.adaptersizelist=adaptersizelist;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
if (adaptersizelist != null) {
return adaptersizelist.size();
}
return 0;
}
@Override
public Object getItem(int position) {
return adaptersizelist.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.custom_spinnertwo, null);
holder.txtproname = (TextView) convertView.findViewById(R.id.text_main_seentwo);
holder.txtproprice = (TextView) convertView.findViewById(R.id.sub_text_seentwo);
holder.checkpack = (CheckBox)convertView.findViewById(R.id.productpack_radio);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
final ProductLandingSizeListModel m = adaptersizelist.get(position);
for(int i=0;i<adaptersizelist.get(position).getPacklistmodel().size();i++)
{
System.out.println("PACK na data"+adaptersizelist.get(position).getPacklistmodel().get(i).getPackList_textUpper());
holder.txtproname.setText(adaptersizelist.get(position).getPacklistmodel().get(i).getPackList_textUpper());
holder.txtproprice.setText(adaptersizelist.get(position).getPacklistmodel().get(i).getPackList_textLower());
}
if (position == mSelectedPositionpack ) {
if (selected == null) {
holder.checkpack.setChecked(true);
selected = holder.checkpack;
}
}
if (position == mSelectedPositionpack )
holder.checkpack.setChecked(true);
else
holder.checkpack.setChecked(false);
holder.checkpack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (selected != null) {
selected.setChecked(false);
}
mSelectedPositionpack =position;
holder.checkpack.setChecked(true);
selected = holder.checkpack;
// selected_pack_text.setText(movieItems.get(position)+" - "+"$"+packItems.get(position));
notifyDataSetChanged();
dialogfpacks.dismiss();
}
});
return convertView;
}
class ViewHolder{
TextView txtproname,txtproprice;
CheckBox checkpack;
}
}