私は、アクティビティがサーバーからList1とList2を取得する非同期タスクで構成されている1つのアプリケーションで作業しています...しかし、そのアプリケーションを開いたときにList2はList1の下に読み込まれ、List2は、だから私はList1を取得するためにスクロールする必要があります...どのようにこの問題を解決するには?事前のおかげでandroid listview layout error
xmlファイル
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="2dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:weightSum="1"
>
<ListView
android:layout_width="match_parent"
android:layout_height="1550dp"
android:id="@+id/list1"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="1550dp"
android:id="@+id/list2"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
javaファイル
public class Mysubscription extends AppCompatActivity {
static Mysubscription INSTANCE;
public static String name2 = "name";
public static String books2 = "books";
public static String registration_fee = "registration_fee";
private Toolbar topToolBar1;
LinearLayout a;
String Subsribed;
Button Renew;
JSONObject jsonobject;
JSONArray jsonarray12;
private Toolbar topToolBar;
ListView listview3;
mysub1 adapter;
mysub2 adapter2;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
private JSONArray gg;
private JSONObject obj;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.subscribe1);
INSTANCE=this;
new DownloadJSON1().execute();
new DownloadJSON2().execute();
}
// DownloadJSON AsyncTask
public class DownloadJSON1 extends AsyncTask<Void, Void, Void> {
API o9=new API();
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
Servicehandler json = new Servicehandler();
jsonarray12 = json.getJSONFromUrl(o9.subscription1);
try {
// Locate the array name in JSON
for (int i = 0; i < jsonarray12.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray12.getJSONObject(i);
// Retrive JSON Objects
map.put("name", jsonobject.getString("name"));
map.put("books", jsonobject.getString("books"));
map.put("registration_fee", jsonobject.getString("registration_fee"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview3 = (ListView) findViewById(R.id.list1);
// Pass the results into ListViewAdapter.java
adapter = new mysub1(Mysubscription.this, arraylist);
// Set the adapter to the ListView
listview3.setAdapter(adapter);
// Close the progressdialog
}
}
public class DownloadJSON2 extends AsyncTask<Void, Void, Void> {
API o9=new API();
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
Servicehandler json = new Servicehandler();
jsonarray12 = json.getJSONFromUrl(o9.subscription1);
try {
// Locate the array name in JSON
for (int i = 0; i < jsonarray12.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray12.getJSONObject(i);
// Retrive JSON Objects
map.put("name", jsonobject.getString("name"));
map.put("books", jsonobject.getString("books"));
map.put("registration_fee", jsonobject.getString("registration_fee"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview3 = (ListView) findViewById(R.id.list2);
// Pass the results into ListViewAdapter.java
adapter2 = new mysub2(Mysubscription.this, arraylist);
// Set the adapter to the ListView
listview3.setAdapter(adapter2);
// Close the progressdialog
}
}
}
シェアも、あなたのソースコードを、どのように – ddb
ソースコードが追加され、それらのリストを読み込むか... –
は、Activityクラスに異なるListViewの変数を宣言し、OnCreateの方法で –