如何像 Instagram 一样制作可加载的 RecyclerView?这样当到达列表末尾时,加载另一条数据。
主页
/
user-214548
cherry's questions
我正在使用 HttpUrlConnection 与服务器通信。
InputStream is = null;
String parammetrs = "clientId=" + client.getId() + "&bikeId=" + 1;
BufferedReader br = null;
String json = null;
try {
URL url = new URL(myURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
connection.getOutputStream().write(parammetrs.getBytes("UTF-8"));
is = connection.getInputStream();
br = new BufferedReader(new InputStreamReader(is));
json = (br.readLine().toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return json;
}
OnPostExecute 对我来说仍然是空的。如何从服务器获取布尔响应、错误 (402, ...)?
我使用 AsyncTask 从 Internet 下载数据的位置有 url1 和 url2。Json 字段类似。唯一区别它们的是 url2 在 json 中没有 end_time 字段。我用一个 AsyncTask 启动两个 url。第一个 url 输出 Recyclerview 中的所有内容,而第二个则没有。我试着把
if(jsonObject.getString("end_time")!=null)
也
if(jsonObject.getString("end_time")!="")
仍然不起作用。
我需要创建两个单独的 AsyncTasks 还是有其他方法?
现在菜单的背景色为黑色。我想把它改成绿色。我试过了android:background="#00FF00"
。不改变。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:background="#00FF00"
>
<item
android:id="@+id/newrent"
android:title="@string/action_new_rent"
app:showAsAction="never"/>
<item
android:id="@+id/deleteme"
android:title="@string/action_delete_me"
app:showAsAction="never"/>
</menu>
在第 44 行抛出错误 Resources$NotFoundException holder.id.setText(record.getId());
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<Record> records = new ArrayList();
public RecyclerViewAdapter(Context context, ArrayList<Rents> arrayList) {
super();
this.records= arrayList;
}
@Override
public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.records_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewAdapter.ViewHolder holder, int position) {
Records record = records.get(position);
Log.e("TEST",""+record.getId());
holder.id.setText(record.getId());
}
@Override
public int getItemCount() {
return records.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
private TextView id;
public ViewHolder(View itemView) {
super(itemView);
id = (TextView)itemView.findViewById(R.id.record_id);
}
}
}
A 是 XML records_item
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/record_image"
android:src="@mipmap/ic_launcher"
android:layout_margin="15dp"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="@+id/record_id"
android:textColor="#000000"
android:layout_toRightOf="@id/record_image"
android:layout_alignTop="@id/record_image"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
有两种类型的用户(服务和客户)。输入登录时,应用程序必须判断用户属于什么类型,并打开相应的界面。客户应该显示菜单,服务应该有订单列表。请帮我解决这个问题。如何实施?