BusinessForSaleActivity
public class BusinessForSaleActivity extends AppCompatActivity {
DatabaseReference databaseLinks;
ListView listViewBusinessForSale;
Button readMore;
ArrayList<BusinessForSale> list;
//CardView cardView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_business_for_sale);
listViewBusinessForSale = (ListView)findViewById(R.id.ListViewBusinessForSale);
list = new ArrayList<>();
databaseLinks = FirebaseDatabase.getInstance().getReference("BusinessList");
databaseLinks.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
list.clear();
try{
for(DataSnapshot businessSnapshot : dataSnapshot.getChildren()){
BusinessForSale b = businessSnapshot.getValue(BusinessForSale.class);
list.add(b);
}
}
catch (Exception ex){
Log.e("Error Descr:",ex.getMessage());
}
BusinessForSaleList adapter=new BusinessForSaleList(BusinessForSaleActivity.this,list);
listViewBusinessForSale.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(BusinessForSaleActivity.this,"Something is wrong",Toast.LENGTH_SHORT).show();
}
});
}
}
BusinessForSaleList================(Adapter class)============
public class BusinessForSaleList extends ArrayAdapter<BusinessForSale> {
private Activity context;
private List<BusinessForSale> businessForSaleList;
public BusinessForSaleList(Activity context,List<BusinessForSale> businessForSaleList){
//super(context,R.layout.list_layout,businessForSaleList);
super(context,R.layout.list,businessForSaleList);
this.context=context;
this.businessForSaleList=businessForSaleList;
}
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View listViewItem=inflater.inflate(R.layout.list,null,true);
ImageView imgBuiness=(ImageView)listViewItem.findViewById(R.id.imgViewBusiness);
TextView txtTitle = (TextView)listViewItem.findViewById(R.id.txtViewTitle);
TextView txtType = (TextView)listViewItem.findViewById(R.id.txtViewType);
TextView txtDescr = (TextView)listViewItem.findViewById(R.id.txtViewDescr);
Button btnReadMore = (Button)convertView.findViewById(R.id.buttonReadMore);
BusinessForSale businessForSale = businessForSaleList.get(position);
Picasso.get().load(businessForSale.getImage().toString()).into(imgBuiness);
txtTitle.setText(businessForSale.getBusiness_Title());
txtType.setText(businessForSale.getBusiness_Type());
txtDescr.setText(businessForSale.getDescription());
return listViewItem;
}
}
BusinessForSaleActivity.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=".BusinessForSaleActivity">
<ListView
android:id="@+id/ListViewBusinessForSale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:footerDividersEnabled="false"
/>
</RelativeLayout>
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"
android:background="#e0e0e0">
<android.support.v7.widget.CardView
android:id="@+id/cardBusinessForSale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">
<LinearLayout
android:id="@+id/L1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgViewBusiness"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_margin="4dp"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/txtViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginBottom="8dp"
android:textColor="#000"
android:textSize="18sp"/>
<TextView
android:id="@+id/txtViewType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#555" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/txtViewDescr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:maxLines="3"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<Button
android:id="@+id/buttonReadMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/PrimaryFlatButton"
android:text="Read More" />
<Button
android:id="@+id/buttonAddToFvrt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/PrimaryFlatButton"
android:text="Add to Favorites" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>][1]
I want to redirect to new Activity on "ReadMore" button click. I am fetching firebase data into a listview using list.xml layout.