我已经尝试并阅读了很多答案,但无法弄清楚如何正确编码...
新闻适配器.java
public class NewsAdapter extends ArrayAdapter{
private static final String DEBUG_TAG = "NEWSADAPTER";
private LayoutInflater inflater;
public NewsAdapter(Activity activity, ArrayList<String> items){
super(activity, R.layout.news_feed, items);
Log.d(DEBUG_TAG, "This is came from the world i know of" + items);
inflater = activity.getWindow().getLayoutInflater();
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
return inflater.inflate(R.layout.news_feed, parent, false);
}
}
新闻提要.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:id="@+id/title"
android:text="@string/news_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="19sp" />
</LinearLayout>
上面代码的输出是...
如何获取items值以及如何设置Text?
最佳答案
这样做:
public class NewsAdapter extends ArrayAdapter{
private static final String DEBUG_TAG = "NEWSADAPTER";
private LayoutInflater inflater;
ArrayList<String> items;
public NewsAdapter(Activity activity, ArrayList<String> items){
inflater = activity.getWindow().getLayoutInflater();
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView
if(v == null)
v = inflater.inflate(R.layout.news_feed, parent, false);
TextView txtTitle = (TextView) v.findViewById(R.id.title);
txtTitle.setText(items.get(position));
return v;
}
}
关于java - 如何扩展 ArrayAdapter 以打印已解析的 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30951744/