Android 使用改装时,我的Listview不返回任何内容
我是新改型的,我只是尝试json解析,我不知道我错过了什么 列表视图未显示。请帮我解决这个问题。我正在使用列表适配器的ListAcivity。这对我来说很奇怪。请帮我解决这个问题。 这是Client.javaAndroid 使用改装时,我的Listview不返回任何内容,android,listview,retrofit,Android,Listview,Retrofit,我是新改型的,我只是尝试json解析,我不知道我错过了什么 列表视图未显示。请帮我解决这个问题。我正在使用列表适配器的ListAcivity。这对我来说很奇怪。请帮我解决这个问题。 这是Client.java public class UtubeClient { private static UtubeApiInterface UtubeService; public static UtubeApiInterface getTwitchTvApiClient() { if (Utube
public class UtubeClient {
private static UtubeApiInterface UtubeService;
public static UtubeApiInterface getTwitchTvApiClient() {
if (UtubeService== null) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("http://tamilpasanga.in")
.build();
UtubeService = restAdapter.create(UtubeApiInterface.class);
}
return UtubeService;
}
public interface UtubeApiInterface {
@GET("/mytuts/list.json")
void getStreams( Callback<List<UtubeChannel>> callback);
}
}
移动阵列适配器
public class MobileArrayAdapter extends ArrayAdapter<UtubeChannel> {
protected static final String TAG = null;
private final Context context;
String outFileName;
private LayoutInflater inflater;
public MobileArrayAdapter(final Context context, List<UtubeChannel > objects) {
super(context, R.layout.listview_item, objects);
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
}
@Override
public View getView(int position, View rowView, ViewGroup parent) {
ViewHolder holder = null;
if (rowView == null) {
rowView = inflater.inflate(R.layout.listview_item, null);
holder = new ViewHolder();
holder.name = (TextView) rowView.findViewById(R.id.name);
holder.url = (TextView) rowView.findViewById(R.id.url);
// viewHolder.button.setTag(viewHolder.text);
// viewHolder.text.setTag(viewHolder.button);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
UtubeChannel channel= getItem(position);
holder.name.setText(channel.getName());
holder.url.setText(channel.getUrl());
return rowView;
}
static class ViewHolder {
public TextView url;
public TextView name;
}
公共类MobileArrayAdapter扩展了ArrayAdapter{
受保护的静态最终字符串标记=null;
私人最终语境;
字符串输出名;
私人充气机;
公共MobileArrayAdapter(最终上下文,列表对象){
super(上下文、R.layout.listview_项、对象);
充气器=(充气器)上下文
.getSystemService(上下文布局\充气机\服务);
this.context=上下文;
}
@凌驾
公共视图getView(int位置、视图行视图、视图组父视图){
ViewHolder=null;
if(rowView==null){
rowView=充气机。充气(R.layout.listview_项,空);
holder=新的ViewHolder();
holder.name=(TextView)rowView.findViewById(R.id.name);
holder.url=(TextView)rowView.findViewById(R.id.url);
//viewHolder.button.setTag(viewHolder.text);
//viewHolder.text.setTag(viewHolder.button);
rowView.setTag(支架);
}否则{
holder=(ViewHolder)rowView.getTag();
}
UtubeChannel通道=getItem(位置);
holder.name.setText(channel.getName());
holder.url.setText(channel.getUrl());
返回行视图;
}
静态类视窗夹{
公共文本视图url;
公共文本视图名称;
}
}您将空列表传递给适配器,然后您尝试从Internet下载数据,但在您不调用时,NotifyDataSetChange更改了列表,没有显示任何内容。因此,您也需要更改代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
streamData = new ArrayList<UtubeChannel>();
// mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
downloadDatainRetrofit();
}
private void downloadDatainRetrofit() {
// mProgressBar.setVisibility(View.VISIBLE);
UtubeClient.getTwitchTvApiClient().getStreams(new Callback<List<UtubeChannel>>() {
@Override
public void success(List<UtubeChannel> utubeChannels, Response response) {
streamData.addAll(utubeChannels) ;
setListAdapter(new MobileArrayAdapter(this,streamData));
}
@Override
public void failure(RetrofitError retrofitError) {
//
}
});
}
2-一次性使用:
adapter = new MobileArrayAdapter(this,streamData);
setListAdapter(adapter);
3-下载数据后使用:
adapter.notifyDatasetChanged();
要刷新列表数据post
MobileArrayAdapter
@shayanpourvatan donetry请调试您的代码,并在MobileArrayAdapter
@shayanpourvatan的构造函数中查找对象的大小,您能解释一下确切的问题吗?谢谢你,伙计,但我已经这样尝试过了,我能知道它不起作用吗?下载DataInRetroFit();setListAdapter(新的MobileArrayAdapter(此为streamData));你试过女巫一号吗?你的数据正确来自互联网吗?是的,我在列表适配器之前调用了DownloadinRetrofit(),反之亦然,我在主要活动中写入了什么
MobileArrayAdapter adapter.
adapter = new MobileArrayAdapter(this,streamData);
setListAdapter(adapter);
adapter.notifyDatasetChanged();