my problem is i want to replace the number to something like an image but i dont know where to start. how to replace the number to drawable? do i need to create adapter?
##edit
https://abhiandroid.com/ui/gridview - i did something like this...
but now how to make it loop ?
public class SelectSeatActivity extends AppCompatActivity {
GridView gridView;
int i;
String[] number = new String[36];
int[] seatImg = {R.drawable.available_img};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_seat);
gridView = (GridView) findViewById(R.id.grid_seat);
for(i = 0; i<number.length; i ){
}
SeatAdapter seatAdapter = new SeatAdapter(getApplicationContext(), seatImg);
gridView.setAdapter(seatAdapter);
CodePudding user response:
If you are using recycler view then try this.
RecyclerView recyclerView = findViewById(R.id.rvNumbers);
recyclerView.setLayoutManager(new GridLayoutManager(this, 6));
adapter = new MyRecyclerViewAdapter(this, data);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
CodePudding user response:
public class SelectSeatActivity extends AppCompatActivity {
GridView gridView;
int i;
String[] number = new String[36];
int[] seatImg = {R.drawable.available_img};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_seat);
gridView = (GridView) findViewById(R.id.grid_seat);
for(i = 0; i<number.length; i ){
}
SeatAdapter seatAdapter = new SeatAdapter(getApplicationContext(), number);
gridView.setAdapter(seatAdapter);
Now your seatAdapter should look something like this
public class SeatAdapter extends BaseAdapter {
Context context;
int numbers[];
LayoutInflater inflter;
public SeatAdapter(Context applicationContext, int[] number) {
this.context = applicationContext;
this.numbers= number;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return logos.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.activity_gridview, null); // inflate the layout
return view;
}
}
And layout resource activity_gridview for SeatAdapter should be something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#fff"
tools:context="com.example.gourav.GridViewExample.SecondActivity">
<ImageView
android:id="@ id/selectedImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/available_img"
android:scaleType="fitXY" />
</RelativeLayout>