Android ListView で RSS フィードからニュース (ベンガル語) を表示したい。アプリを実行すると、画面に何も表示されません。コードを共有しています。もし私がここで何か間違ったことをしていたら、あなたたちが私に教えてくれたらうれしいです
MainActivity.java
package com.andodev.android.reader;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.andodev.android.reader.data.RssItem;
import com.andodev.android.reader.listeners.ListListener;
import com.andodev.android.reader.util.RssReader;
public class NewsActivity extends Activity {
/**
* This method creates main application view
*/
List<RssItem> listItems = new ArrayList<RssItem>();
CustomAdapter adapt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set view
setContentView(R.layout.main);
try {
// Create RSS reader
RssReader rssReader = new RssReader("http://www.amaderbarisal.com/feed/");
// Get a ListView from main view
ListView itcItems = (ListView) findViewById(R.id.list);
adapt = new CustomAdapter(this, listItems);
itcItems.setAdapter(adapt);
// Set list view item click listener
itcItems.setOnItemClickListener(new ListListener(rssReader.getItems(), this));
} catch (Exception e) {
Log.e("ITCRssReader", e.getMessage());
}
}
}
カスタムアダプター
/**
*
*/
package com.andodev.android.reader;
import java.util.List;
import com.andodev.android.reader.data.RssItem;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class CustomAdapter extends ArrayAdapter<RssItem> {
List<RssItem> listItems;
Context context;
public CustomAdapter(Context context,List<RssItem> listItems) {
super(context,R.layout.custom);
// TODO Auto-generated constructor stub
this.context = context;
this.listItems = listItems;
}
public RssItem getItem(int position){
return listItems.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
RssHolder holder = new RssHolder();
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.custom, null);
TextView tv = (TextView)v.findViewById(R.id.name);
Typeface myTYpe = Typeface.createFromAsset(context.getAssets(), "solaiman-lipi.ttf");
tv.setTypeface(myTYpe);
holder.RssTitle = tv;
v.setTag(holder);
}
else{
holder = (RssHolder) v.getTag();
RssItem p = listItems.get(position);
holder.RssTitle.setText(p.getTitle());
}
return v;
}
private static class RssHolder{
public TextView RssTitle;
}
}
custom.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"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textStyle="bold"
/>
</LinearLayout>
main.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">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"/>
</LinearLayout>