public class RVAdapter extends RecyclerView.Adapter<RVAdapter.ContentViewHolder> {
public interface OnItemClickListener{
void onItemClicked(int position);
}
public static class ContentViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
CardView cv;
TextView cvTitle;
TextView cvContent;
ImageView cvPhoto;
OnItemClickListener cvClickListener;
public ContentViewHolder(View itemView, OnItemClickListener clickListener) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cv);
cvTitle = (TextView) itemView.findViewById(R.id.text_title);
cvContent = (TextView) itemView.findViewById(R.id.text_content);
cvPhoto = (ImageView) itemView.findViewById(R.id.text_photo);
cvClickListener = clickListener;
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
cvClickListener.onItemClicked(getAdapterPosition());
Log.i("RecyclerView", "Вы щёлкнули на позиции " + getAdapterPosition());
}
}
List<CardContent> mCardContents;
public RVAdapter(List<CardContent> mCardContents, OnItemClickListener itemClickListener) {
this.mCardContents = mCardContents;
this.mItemClickListener = itemClickListener;
}
@Override
public int getItemCount() {
return mCardContents.size();
}
@Override
public ContentViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview, viewGroup, false);
ContentViewHolder pvh = new ContentViewHolder(v, mItemClickListener);
return pvh;
}
@Override
public void onBindViewHolder(ContentViewHolder contentViewHolder, int i) {
contentViewHolder.cvTitle.setText(mCardContents.get(i).title);
contentViewHolder.cvContent.setText(mCardContents.get(i).content);
contentViewHolder.cvPhoto.setImageResource(mCardContents.get(i).photoId);
//Log.i("RecyclerView", "Позиция " + i);
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
}
Dialog_SpinnerSelect dialog = new Dialog_SpinnerSelect(getActivity());
наDialog_SpinnerSelect dialog = new Dialog_SpinnerSelect(this);
;private Context context;
public Dialog_SpinnerSelect(Context context) {
this.context = context;
builder = new AlertDialog.Builder(context);
}
наprivate Fragment_Layers fragment;
public Dialog_SpinnerSelect(Fragment_Layers fragment) {
this.fragment = fragment;
builder = new AlertDialog.Builder(fragment.getActivity());
}
;public void onClick(DialogInterface dialog, int arg1) {
((ResultListener) context).onSpinnerSelectResult(keys[selecteditemid]);
}
наpublic void onClick(DialogInterface dialog, int arg1) {
((ResultListener) fragment).onSpinnerSelectResult(keys[selecteditemid]);
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yandex.ru"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//запрос всех activity, которые могут этот intent обработать
List<ResolveInfo> resInfo = activity.getPackageManager().queryIntentActivities(intent, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (/*здесь проверяй info на предмет нужной тебе activtiy*/) {
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
intent.setPackage(info.activityInfo.packageName);
context.startActivity(intent);
break;
}
}
}
}
class CocktailItem{
String title;
String description;
Bitmap icon;
}
AdapterView.OnItemClickListener() {
@Override
public
void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
CocktailItem item = (CocktailItem) parent.getAdapter().getItem(position);
AlertDialog.Builder builder = new AlertDialog.Builder(ShotDrinks.this);
builder.setTitle(item.title)
.setMessage(item.description)
.setCancelable(true)
.setIcon(R.drawable.ic_launcher)
...
}
};
((ActionBarActivity)getActivity()).getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
<activity
android:name=".SubActivity"
android:label="@string/title_activity_sub"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>