我使用改装来显示数据,但数据没有显示出来。我不知道哪里出错了。在logcat中,我得到的响应如下:
2019-12-26 20:34:39.847 28305-28305/com.example.androidtutorial E/helloash: [com.example.androidtutorial.GetAheadFolder.JavaDatum@36ebcd9]
我需要帮助。。谢谢
GetAHeadModelsnext:
public class GetAHeadModelsnext{
@SerializedName("id")
@Expose
private String id;
@SerializedName("title")
@Expose
private String title;
@SerializedName("java_data")
@Expose
private List<JavaDatum> java_data ;
@SerializedName("xml_data")
@Expose
private List<XmlDatum> xmlData;
public GetAHeadModelsnext(String id, String title, List<JavaDatum> java_data, List<XmlDatum> xmlData) {
this.id = id;
this.title = title;
this.java_data = java_data;
this.xmlData = xmlData;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<JavaDatum> getJavaData() {
return java_data;
}
public void setJavaData(List<JavaDatum> javaData) {
this.java_data = javaData;
}
public List<XmlDatum> getXmlData() {
return xmlData;
}
public void setXmlData(List<XmlDatum> xmlData) {
this.xmlData = xmlData;
}
子模型(ListJavaDatum):
public class JavaDatum {
@SerializedName("file_name")
@Expose
private String fileName;
@SerializedName("code")
@Expose
private String code;
public JavaDatum(String fileName, String code) {
this.fileName = fileName;
this.code = code;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}}
界面:
public interface DescriptService {
@GET("/v1/android_tutorials/single_advance?")
Call<GetAHeadModelsnext> getaheadjava(@Query("advance_id") String id);}
活动:
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
/*Create handle for the RetrofitInstance interface*/
progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage("Loading....");
progressDialog.show();
Intent intent = getActivity().getIntent();
String id = intent.getStringExtra("idGHnext");
Log.e("ashwiniiii", String.valueOf(id));
GetAheadApiService service = GetAheadApiClient.getRetrofitInstance().create(GetAheadApiService.class);
Call<GetAHeadModelsnext> call = service.getaheadjava(id);
call.enqueue(new Callback<GetAHeadModelsnext>() {
@Override
public void onResponse(Call<GetAHeadModelsnext> call, Response<GetAHeadModelsnext> response) {
progressDialog.dismiss();
List<JavaDatum> retro=response.body().getJavaData();
generateDataList(retro);
Log.e("helloash", String.valueOf(response.body().getJavaData()));
}
@Override
public void onFailure(Call<GetAHeadModelsnext> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(getContext(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
private void generateDataList(List<JavaDatum> photoList) {
recyclerView = getView().findViewById(R.id.nextGHrecycle);
LinearLayoutManager manager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
adapter = new JavaGetAheadAdapter(getContext(),photoList);
recyclerView.setAdapter(adapter);
}}
适配器:
public class JavaGetAheadAdapter extends RecyclerView.Adapter<JavaGetAheadAdapter.CustomViewHolder> {
List<JavaDatum> GHmdel;
Context context;
public JavaGetAheadAdapter(Context context,List<JavaDatum> employees) {
this.GHmdel = employees;
this.context = context;
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.getaheadnext_item, parent, false);
return new CustomViewHolder(itemView);
}
@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
holder.employeeName.setText(GHmdel.get(position).getFileName());//
holder.textView.setText(GHmdel.get(position).getCode());
Log.d("adapter",GHmdel.get(position).getFileName());
Log.d("adapter2",GHmdel.get(position).getCode());
}
@Override
public int getItemCount() {
return GHmdel.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
public TextView employeeName;
TextView textView;
public CustomViewHolder(View view) {
super(view);
employeeName = (TextView) view.findViewById(R.id.detailsgetaheadtitle);
textView = view.findViewById(R.id.detailsgetahead);}}}
我的json:
{
"id": "1",
"title": "ViewPager and TabHost",
"java_data": [
{
"file_name": "ListDisplay.java",
"code": "package com.example.ListDisplay;\r\n\r\nimport android.os.Bundle;\r\nimport android.app.Activity;\r\nimport android.view.Menu;\r\nimport android.widget.ArrayAdapter;\r\nimport android.widget.ListView;\r\n\r\npublic class ListDisplay extends Activity {\r\n // Array of strings...\r\n String[] mobileArray = {\"Android\",\"IPhone\",\"WindowsMobile\",\"Blackberry\",\r\n \"WebOS\",\"Ubuntu\",\"Windows7\",\"Max OS X\"};\r\n \r\n @Override\r\n protected void onCreate(Bundle savedInstanceState) {\r\n super.onCreate(savedInstanceState);\r\n setContentView(R.layout.activity_main);\r\n \r\n ArrayAdapter adapter = new ArrayAdapter<String>(this, \r\n R.layout.activity_listview, mobileArray);\r\n \r\n ListView listView = (ListView) findViewById(R.id.mobile_list);\r\n listView.setAdapter(adapter);\r\n }\r\n}"
}
],
"xml_data": [
{
"file_name": "activity_main.xml",
"code": "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\r\n xmlns:tools=\"http://schemas.android.com/tools\"\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"match_parent\"\r\n android:orientation=\"vertical\"\r\n tools:context=\".ListActivity\" >\r\n\r\n <ListView\r\n android:id=\"@+id/mobile_list\"\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"wrap_content\" >\r\n </ListView>\r\n \r\n</LinearLayout>\r\nimport android.os.Bundle;\r\nimport android.app.Activity;\r\nimport android.view.Menu;\r\nimport android.widget.ArrayAdapter;\r\nimport android.widget.ListView;\r\n\r\npublic class ListDisplay extends Activity {\r\n // Array of strings...\r\n String[] mobileArray = {\"Android\",\"IPhone\",\"WindowsMobile\",\"Blackberry\",\r\n \"WebOS\",\"Ubuntu\",\"Windows7\",\"Max OS X\"};\r\n \r\n @Override\r\n protected void onCreate(Bundle savedInstanceState) {\r\n super.onCreate(savedInstanceState);\r\n setContentView(R.layout.activity_main);\r\n \r\n ArrayAdapter adapter = new ArrayAdapter<String>(this, \r\n R.layout.activity_listview, mobileArray);\r\n \r\n ListView listView = (ListView) findViewById(R.id.mobile_list);\r\n listView.setAdapter(adapter);\r\n }\r\n}"
},
{
"file_name": "strings.xml",
"code": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<resources>\r\n <string name=\"app_name\">ListDisplay</string>\r\n <string name=\"action_settings\">Settings</string>\r\n</resources>"
},
{
"file_name": "activity_listview.xml",
"code": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<!-- Single List Item Design -->\r\n\r\n<TextView xmlns:android=\"http://schemas.android.com/apk/res/android\"\r\n android:id=\"@+id/label\"\r\n android:layout_width=\"fill_parent\"\r\n android:layout_height=\"fill_parent\"\r\n android:padding=\"10dip\"\r\n android:textSize=\"16dip\"\r\n android:textStyle=\"bold\" >\r\n</TextView>"
}
]
}
假设数据存在,请尝试进行以下更改
public class JavaGetAheadAdapter extends RecyclerView.Adapter<JavaGetAheadAdapter.CustomViewHolder> {
List<JavaDatum> GHmdel = new ArrayList(); //new change
Context context;
//removed the list from constructor
public JavaGetAheadAdapter(Context context) {
this.GHmdel = employees;
}
//new method for updating the data items
public void updateData(List<JavaDatum> employees){
this.GHmdel.addAll(employees);
notifyDataSetChanged();
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.getaheadnext_item, parent, false);
return new CustomViewHolder(itemView);
}
@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
holder.employeeName.setText(GHmdel.get(position).getFileName());//
holder.textView.setText(GHmdel.get(position).getCode());
Log.d("adapter",GHmdel.get(position).getFileName());
Log.d("adapter2",GHmdel.get(position).getCode());
}
@Override
public int getItemCount() {
return GHmdel.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
public TextView employeeName;
TextView textView;
public CustomViewHolder(View view) {
super(view);
employeeName = (TextView) view.findViewById(R.id.detailsgetaheadtitle);
textView = view.findViewById(R.id.detailsgetahead);}}}
在呼叫端,只需进行下面提到的更改。
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
/*Create handle for the RetrofitInstance interface*/
progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage("Loading....");
progressDialog.show();
Intent intent = getActivity().getIntent();
String id = intent.getStringExtra("idGHnext");
Log.e("ashwiniiii", String.valueOf(id));
// new changes
generateDataList(view);
GetAheadApiService service = GetAheadApiClient.getRetrofitInstance().create(GetAheadApiService.class);
Call<GetAHeadModelsnext> call = service.getaheadjava(id);
call.enqueue(new Callback<GetAHeadModelsnext>() {
@Override
public void onResponse(Call<GetAHeadModelsnext> call, Response<GetAHeadModelsnext> response) {
progressDialog.dismiss();
List<JavaDatum> retro=response.body().getJavaData();
//new changes
adapter.updateData(retro);
Log.e("helloash", String.valueOf(response.body().getJavaData()));
}
@Override
public void onFailure(Call<GetAHeadModelsnext> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(getContext(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
//new changes goes here
private void generateDataList(View view) {
recyclerView = view.findViewById(R.id.nextGHrecycle);
LinearLayoutManager manager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
adapter = new JavaGetAheadAdapter(getContext());
recyclerView.setAdapter(adapter);
}}
尝试在下面评论它是否仍然有效。
尝试在你的接口GET方法中删除v1之前的/并把它添加到你的基本url中。总之在任何翻新界面的方法中不要以/开头。
可能是我有问题。问题就在这里< code > @ GET("/v1/Android _ tutorials/single _ advance?")你有< code >?在您的< code>url的末尾,并且您还有< code > @ Query(" advance _ id ")字段,这意味着您的请求包含两个< code >?。你要求目前看起来像这样。
/v1/android_tutorials/single_advance??advance_id="xxxx"
请记住,当您将< code > @ Query(" advance _ id ")添加到您的请求时,默认情况下会添加< code >?到您的。所以去掉< code >?从您的< code>url端。你的网址应该是这样的
@GET("/v1/android_tutorials/single_advance")
这里是第一次Eclipse用户。我正在使用“Eclipse IDE for JavaScript Web Developers”Indigo Service Release2,并将EaselJS库包含在我的项目中。本地主机上的HTTP预览是我的服务器。 我的问题是,当我对正在处理的index.html文件进行更改并选择“运行”时,HTTP预览(在Eclipse IDE窗口的一部分中运行)不会显示更
我试图在我的网格上创建一个贴花使用three.js和反应-三纤维。我相信我正确地设置了网格和材料,但由于某种原因,贴花没有出现在画布上。 这是包含模型、背板和贴花的父组件。 这是我从. glb文件创建t恤网格的组件的一部分。网格传递回父节点,然后传递到Decal组件。 以下是我尝试设置贴花网格的方式: 我没有得到任何错误,贴花只是没有出现。我希望有人有一些见解。没有太多关于贴花几何体与3J在那里,
问题内容: 我有一个图标图标,该图标在Chrome中没有显示(我不确定其他浏览器,因为我仅使用Chrome),但是奇怪的是,如果我在显示的URL栏中键入图标的路径! 为什么图标不出现? 问题答案: 快取 清除缓存。并测试其他浏览器。 有些地方可以通过添加URL参数来获取更新的网站图标:在链接href之后,它更改了资源链接,因此可以在没有缓存的情况下加载网站图标(感谢@Stanislav)。 网站图
所以我在玩JPanel和JFrames,我注意到我创建的JPanel在添加到Jframe对象时没有显示。注意,当我在Jframe构造函数中创建了一个JPanel,并在将其添加到Jframe之前提供了JPanel参数时,它起了作用。然而,现在我使用的是我创建的JPanel对象,它不再工作了。这就是我所做的。 编辑:事实上,我想我发现了错误。JPanel有它的绘制方法,当删除时,它允许Jframe显示
问题内容: 我是Java初学者 我试图制作我的jframe节目,但没有 它不起作用 问题答案: 我认为您没有正确声明您的JFrame。这是创建简单框架的示例:
问题内容: 我是iOS的新手。我正在尝试显示一个弹出菜单,但是我却无法显示菜单。请帮忙。这是我的代码: 请帮助我显示弹出菜单。 先感谢您。 问题答案: