我的应用程序中有一个片段,它从parse.com获取数据并将其显示在ListView中。在Android ListView中单独显示的TextViews
我从Parse中检索两个字符串值。我的问题是,两个字符串值被显示在在ListView单独行(见下图)
http://postimg.org/image/vsaw8lsbh/33225549/
我的目标是具有相同的行作为对象中的时间。
listview_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
listview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:padding="5sp"
android:textSize="15sp" />
fragmentClass
public class TuesdayFragment extends Fragment {
// Declare Variables
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ArrayAdapter<String> adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View v = inflater.inflate(R.layout.listview_main, container, false);
Parse.initialize(getActivity(), "***parsekey***", "***parsekey***");
new RemoteDataTask().execute();
return v;
}
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(getActivity());
// Set progressdialog title
mProgressDialog.setTitle("Loading Programme, Please Wait :)");
// Set progressdialog message
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject> ("Program");
query.orderByAscending("pSession");
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result){
listview = (ListView) getView().findViewById(R.id.listview);
adapter = new ArrayAdapter<String>(getActivity(), R.layout.listview_item);
for (ParseObject country : ob) {
adapter.add((String) country.get("pSubject"));
adapter.add((String) country.get("pTime"));
}
listview.setAdapter(adapter);
mProgressDialog.dismiss();
}
}
}
你需要一些比ArrayAdapter更复杂的东西。 SimpleAdapter可能是一个简单的方法。 –
njzk2