B
Braesident
Ambitioniertes Mitglied
- 1
Hallo Leute,
wie im Titel schon angedeutet hätte ich gern ein RecyclerView in einem AlertDialog. Aufgerufen wird der Dialog in meiner Mainactivity aus einem FabHandler heraus. Bisher sind alle versuche fehlgeschlagen. Kann mir da vllt jemand weiter helfen?
wie im Titel schon angedeutet hätte ich gern ein RecyclerView in einem AlertDialog. Aufgerufen wird der Dialog in meiner Mainactivity aus einem FabHandler heraus. Bisher sind alle versuche fehlgeschlagen. Kann mir da vllt jemand weiter helfen?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/id_ivJoblist"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="#FFFFBB33"
android:contentDescription="@string/app_name"
android:scaleType="center"
android:src="@drawable/image" />
<android.support.v7.widget.RecyclerView
android:id="@+id/id_rvJoblist"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/id_tvJob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/id_ibtnSend"
android:layout_alignParentStart="true"
android:text="TextView" />
<ImageButton
android:id="@+id/id_ibtnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/ic_menu_send"
android:layout_alignTop="@+id/id_tvLfNr"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Code:
public class JoblistAdapterRecyclerView extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Context context;
String[] items;
public JoblistAdapterRecyclerView(Context context, String[] items){
this.context = context;
this.items = items;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View row = inflater.inflate(R.layout.joblist_row, parent, false);
Item item = new Item(row);
return item;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((Item)holder).tvJob.setText(items[position]);
}
@Override
public int getItemCount() {
return items.length;
}
public class Item extends RecyclerView.ViewHolder{
TextView tvJob;
public Item(View itemView){
super(itemView);
tvJob = (TextView) itemView.findViewById(R.id.id_tvJob);
}
}
}
Code:
public class MainActivity extends Activity {
private MyMainLayoutBinding binding;
private boolean isFabMenuOpen = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// FAB Menü
binding = DataBindingUtil.setContentView(this, R.layout.my_main_layout);
binding.setFabHandler(new FabHandler());
}
public class FabHandler {
public void onClickJobList(View view) {
String[] items = {"item 0", "Item 1"};
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
//final View dialogView = inflater.inflate(R.layout.settings_login, null);
final RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.joblist_dialog, null);
//final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.id_rvJoblist);
if(recyclerView == null)
Log.i(LOG_TAG, "VIEW is NULL");
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
recyclerView.setAdapter(new JoblistAdapterRecyclerView(MainActivity.this, items));
AlertDialog jobListDialog = new AlertDialog
.Builder(MainActivity.this)
/*.setTitle("Aufträge")*/
.setView(recyclerView)
.create();
jobListDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Abbrechen",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
jobListDialog.show();
}
public void onClickMore(View view) {
collapseFabMenu();
openOptionsMenu();
}
}
}