Professional Documents
Culture Documents
//activity_list.xml
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
//list_data.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginLeft="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:textColor="#111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"/>
<TextView
android:id="@+id/txt_description"
android:textColor="#111"
android:layout_marginLeft="10dp"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:textColor="#111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sell Price:"/>
<TextView
android:id="@+id/txt_sell_price"
android:textColor="#111"
android:layout_marginLeft="10dp"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
this.description = description;
this.sell_price = sell_price;
}
public String getDescription() {
return description;
return sell_price;
//myAdapter.java
private List<item_data>list_data;
this.list_data = item_data;
@Override
View view=
LayoutInflater.from(parent.getContext()).inflate(R.layout.list_data,parent,false);
@Override
item_data listData=list_data.get(position);
holder.txtdescription.setText(listData.getDescription());
holder.txtsell_price.setText(listData.getSell_price());
}
@Override
return list_data.size();
super(itemView);
txtdescription=(TextView)itemView.findViewById(R.id.txt_description);
txtsell_price=(TextView)itemView.findViewById(R.id.txt_sell_price);
//mainActivity.java
btnview.setOnClickListener(new View.OnClickListener() {
@Override
startActivity(intent);
});
//ListActivity.java
@Override
super.onCreate(savedInstanceState);
mContext = getApplicationContext();
setContentView(R.layout.activity_list);
rv=(RecyclerView)findViewById(R.id.recyclerview);
rv.setHasFixedSize(true);
rv.setLayoutManager(new LinearLayoutManager(this));
list_data=new ArrayList<>();
adapter=new myAdapter(list_data);
getItemData();
try {
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("url","url"+ myURL);
// stringRequest=new StringRequest(Request.Method.GET,
@Override
public void onResponse(JSONObject response) {
try {
//JSONArray array=jsonObject.getJSONArray("data");
JSONArray array=response.getJSONArray("data");
JSONObject ob=array.getJSONObject(i);
item_data listData=new
item_data(ob.getString("description")
,ob.getString("sell_price"));
list_data.add(listData);
rv.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}, new Response.ErrorListener() {
@Override
});
requestQueue.add(jsonRequest);