-1
List View僅顯示數據中的第一項。我如何讓它顯示數組列表中的所有數據。我認爲它是因爲我在地圖bur中使用了相同的密鑰,所以我如何改變它並讓它出現。任何幫助表示讚賞。ListView僅顯示arraylist中的第一項
package menu.saryal.example.com.menu;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
/**
* A placeholder fragment containing a simple view.
*/
public class ItemOrderedFragment extends Fragment {
private ArrayAdapter<String> itemTitle;
public final static String EXTRA_TEXT = "menu.saryal.example.com.menu";
public ItemOrderedFragment getThisItemOrderedFragment() {
return thisItemOrderedFragment;
}
ItemOrderedFragment thisItemOrderedFragment = this;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item_ordered, container, false);
final MenuDbHelper dbHandler = new MenuDbHelper(this.getActivity());
ArrayList<menuDescription> data = dbHandler.readData();
// Get a reference to the ListView, and attach this adapter to it.
ListView listView = (ListView) rootView.findViewById(R.id.fragment_item_ordered_list_view);
ArrayList<HashMap<String, String>> albumsList;
albumsList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
for(menuDescription x:data){
map.put("Title", x.getTitle());
map.put("Description", x.getDescription());
}
// adding HashList to ArrayList
albumsList.add(map);
ListAdapter adapter = new SimpleAdapter(
this.getActivity(),
albumsList,
R.layout.list_item_with_image,
new String[] { "Title", "Description"},
new int[] {R.id.list_item_with_image_text_view, R.id.recepit_cost_text_view });
if (data.size()>0){
listView.setAdapter(adapter);
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String title = itemTitle.getItem(position);
menuDescription item = dbHandler.findByTitle(title);
String cost_string = "" + item.getCost();
String totalCost_string = "" + item.totalCost;
String totalOrder_string = "" + item.getTotalOrder();
String[] transfer_data = {item.getTitle(),item.getDescription(),cost_string,totalCost_string,totalOrder_string,item.getImage()};
Intent intent = new Intent(getActivity(), EditDetailPage.class);
intent.putExtra(EXTRA_TEXT, transfer_data);
startActivity(intent);
}
});
dbHandler.close();
return rootView;
}
}
'爲(menuDescription X:數據){'你需要創建一個新的地圖,並在此循環 – njzk2
感謝您添加到陣列中。很好的幫助 –