的ListView中的GridView中我必須在android應用程序中的文本和列表視圖中創建自定義gridview。在android中面對android.view.InflateException的問題
這裏我顯示在gridview的類別名稱,並且如果類別名稱是匹配,這意味着必須顯示該列表是在相應的下面categoryname.here列表視圖顯示我所提到的下面教程:my reference tutorial
我在gridview.here中顯示類別名稱,如果類別名稱是notchbolly,這意味着gridview列表項顯示在notchbolly類別名稱上方的水平listview中。
但在這裏我需要運行的應用程序只意味着在所有類別執行的其他部分name.whats錯誤的,我code.pls給我這些解決方案...
我用下面的代碼:
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
ListAdapter adapter;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView) vi.findViewById(R.id.title);
ListView imageView = (ListView) vi
.findViewById(R.id.grid_item_image);
HashMap<String, String> item = new HashMap<String, String>();
item = data.get(position);
// Setting all values in listview
title.setText(item.get(MainActivity.KEY_TITLE));
if (item.equals("notchbolly")) {
listview.setAdapter(this);
} else {
listview.setBackgroundResource(R.drawable.rihanna);
}
return vi;
}
MainActivity.java:
public class MainActivity extends Activity {
static final String URL = "http://webservices/new_feed_articls.xml";
static String KEY_CATEGORY = "Categories";
static final String KEY_TITLE = "Category";
static final String KEY_TITLENAME = "name";
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_TITLE);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String> ();
Element e = (Element) nl.item(i);
map.put(KEY_TITLE,((Element)nl.item(i)).getAttribute(KEY_TITLENAME));
// map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
songsList.add(map);
}
GridView list = (GridView) findViewById(R.id.listView1);
adapter = new LazyAdapter(this, songsList);
list.setAdapter(adapter);
請給我these.whats錯在我的代碼解決方案????
編輯:
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.example.notch.HorizontalListView
android:id="@+id/grid_item_image"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#FFFFFF"
/>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</TextView>
</LinearLayout>
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<GridView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
/>
我已經顯示的類別名稱上gridview.here如果產品類別名稱爲這意味着gridvi ew列表項顯示在notchbolly類別名稱上方的水平列表視圖中。
但在這裏我需要運行的應用程序只意味着在所有類別執行的其他部分name.whats錯誤的,我code.pls給我...
這裏的其他部分只執行了這些解決方案..
請發表您的XML文件的問題,看來在那裏(無論是list_row和活動佈局請): XML文件行#11:錯誤充氣類 –
2013-02-18 04:33:40
@ daniel_c05請看我更新的問題,並給我的解決方案對於這些... – android 2013-02-18 05:05:17