我正在以JSON形式从MySQL数据库获取数据并显示在自定义列表view.list视图中很长。现在我想要当我在主要活动中单击按钮时,将我重定向到列表视图,移至我离开的位置。
提前致谢。

    public class ShowParahDetail extends AppCompatActivity {
ProgressDialog pd;
CustomAdapter c;
ArrayList<Ayah_textAR> ar_ayahAR;
ArrayList<Ayah_textTR> ar_ayah_TR;
JazzyListView lv;
String intent_parah_ID;
String intent_parahName;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_parah_detail);
    intent_parah_ID=getIntent().getExtras().getString("parahID");
    intent_parahName=getIntent().getExtras().getString("parahName");
    setTitle(intent_parahName);
    pd = new ProgressDialog(ShowParahDetail.this, R.style.pdtheme);
    pd.setCancelable(false);
    pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
    pd.show();
    lv= (JazzyListView) findViewById(R.id.lvparahDetail);

    ar_ayahAR = new ArrayList<>();
    ar_ayah_TR = new ArrayList<>();
    ShowDataAR();
    ShowTranslationUR();
}

private void ShowTranslationUR() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            String RecievedString = "";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("parahid", intent_parah_ID);
            Network network = new Network("showParahTranslationUR.php", params);

            try {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                RecievedString = network.ToRecieveDataFromWeb();
                JsonParsing jsonparsing = new JsonParsing(RecievedString);
                ArrayList<HashMap<String, String>> convertedarraydata = jsonparsing.ParsejsonArray(RecievedString);
                for (int i = 0; i < convertedarraydata.size(); i++) {
                    HashMap<String, String> positionHashmap;
                    positionHashmap = convertedarraydata.get(i);

                    String str_ayahText = positionHashmap.get("verseText");
                    String str_verseID = positionHashmap.get("verse_id");
                    String str_surahID = positionHashmap.get("surah_id");


                    Ayah_textTR ayahTR = new Ayah_textTR();
                    ayahTR.ayah_textTR = str_ayahText;
                    ayahTR.verse_id = str_verseID;
                    ayahTR.surah_id = str_surahID;
                    ar_ayah_TR.add(ayahTR);
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

private void ShowDataAR() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            String RecievedString = "";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("parahid", intent_parah_ID);
            Network network = new Network("showParahDetails.php", params);

            try {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                RecievedString = network.ToRecieveDataFromWeb();
                JsonParsing jsonparsing = new JsonParsing(RecievedString);
                ArrayList<HashMap<String, String>> convertedarraydata = jsonparsing.ParsejsonArray(RecievedString);
                for (int i = 0; i < convertedarraydata.size(); i++) {
                    HashMap<String, String> positionHashmap;
                    positionHashmap = convertedarraydata.get(i);
                    String str_ayahID = positionHashmap.get("verse_id");
                    String str_ayahText = positionHashmap.get("verseText");

                    Ayah_textAR ayahText = new Ayah_textAR();
                    ayahText.ayah_id = str_ayahID;
                    ayahText.ayah_textAR = str_ayahText;
                    ar_ayahAR.add(ayahText);
                }

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (ShowParahDetail.this == null)
                    return;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Parcelable state = lv.onSaveInstanceState();
                        lv.onRestoreInstanceState(state);
                        c = new CustomAdapter(ShowParahDetail.this, R.layout.cstm_parah, R.id.tv_parahNAME, ar_ayahAR);
                        lv.setAdapter(c);
                        if(pd!=null){
                            pd.dismiss();
                            pd = null;
                        }
                    }
                });
            }
        }
    }).start();
}


class CustomAdapter extends ArrayAdapter<Ayah_textAR> {
    public CustomAdapter(Context context, int resource, int textViewResourceId, ArrayList<Ayah_textAR> objects) {
        super(context, resource, textViewResourceId, objects);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.cstm_ayah, parent, false);

        final TextView tv_ayah_text = (TextView) v.findViewById(R.id.tv_ayahText);
        final TextView tv_ayahTR = (TextView) v.findViewById(R.id.tv_ayahTR);

        try {
            Ayah_textAR ayah = ar_ayahAR.get(position);
            tv_ayah_text.setText(ayah.ayah_id + " : " + ayah.ayah_textAR);
            Ayah_textTR parahTR = ar_ayah_TR.get(position);
            tv_ayahTR.setText(parahTR.ayah_textTR);
        }catch (Exception e){
            notifyDataSetChanged();
        }

        });
        return v;
    }
}
public class Ayah_textAR {
    String ayah_id;
    String ayah_textAR;
}
public class Ayah_textTR {
    String verse_id;
    String ayah_textTR;
    String surah_id;
}



@Override
public void onDestroy() {
    super.onDestroy();
    if (pd != null) {
        pd.dismiss();
        pd = null;
    }
}


}

最佳答案

您有三个活动,A,B和C。从Intent开始活动B。并且还可以有目的地开始您的活动C。然后,如果您开始活动A并希望保存C中存在的数据,则可以有意地开始活动A。并且不要完成活动C。如果要恢复活动C,只需从活动A调用onBackPressed()。别忘了完成活动A。为此调用onFinish()

09-10 06:10
查看更多