Tengo un adapter que me carga los ítems de un list view y tengo un fragment que los toma.
Adapter:
package com.dmbteam.hotelapp.adapters;
import java.util.ArrayList;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.dmbteam.hotelapp.ApplicationContext;
import com.dmbteam.hotelapp.MainActivity;
import com.dmbteam.hotelapp.R;
import com.dmbteam.hotelapp.fragments.NavigationBarFragment;
import com.dmbteam.hotelapp.fragments.RatesFragment;
import com.dmbteam.hotelapp.fragments.ReservationFragment;
import com.dmbteam.hotelapp.models.HotelReservationContactItem;
import com.dmbteam.hotelapp.models.RatesPageSettings;
import com.dmbteam.hotelapp.models.RoomRatesItem;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import static android.R.attr.fragment;
import static android.support.v4.app.ActivityCompat.startActivity;
/**
* The adapter used for the Rates Fragment
*
*/
public class RatesListAdapter extends ArrayAdapter<RoomRatesItem> {
private ApplicationContext mContext;
private ImageLoader mImageLoader;
private DisplayImageOptions mImageOptions;
/**
*
* @param context
* the application context
* @param items
* the RoomRates items to show
*/
public RatesListAdapter(ApplicationContext context,
ArrayList<RoomRatesItem> items) {
super(context, 0, items);
mContext = context;
mImageLoader = ImageLoader.getInstance();
mImageOptions = com.dmbteam.hotelapp.MainActivity.buildImageOptions(
ImageScaleType.IN_SAMPLE_INT, true, true,
MainActivity.dipsToPixels(mContext, 5), 0,
R.drawable.action_bar_hotel_logo);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(mContext).inflate(
R.layout.rates_list_item, null);
if (position % 2 > 0) {
convertView.setBackgroundColor(mContext.getResources().getColor(
R.color.drawer_grey_light));
} else {
convertView.setBackgroundColor(mContext.getResources().getColor(
R.color.drawer_grey));
}
RoomRatesItem item = getItem(position);
TextView title = (TextView) convertView
.findViewById(R.id.ratesListTitleTextView);
title.setText(item.getRoomTitle());
TextView description = (TextView) convertView
.findViewById(R.id.ratesListDescriptionTextView);
description.setText(item.getRoomDescription());
TextView price = (TextView) convertView.findViewById(R.id.ratesListRatesTextView);
price.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/*Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
intent.addCategory("android.intent.category.LAUNCHER");
intent.setData(Uri.parse("http://www.google.com"));
mContext.startActivity(intent);*/
}
});
ImageView image = (ImageView) convertView
.findViewById(R.id.ratesListItemImageView);
mImageLoader.displayImage(item.getRoomPicture(mContext), image,
mImageOptions);
return convertView;
}
}
Frament:
package com.dmbteam.hotelapp.fragments;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.dmbteam.hotelapp.ApplicationContext;
import com.dmbteam.hotelapp.R;
import com.dmbteam.hotelapp.adapters.RatesListAdapter;
import com.dmbteam.hotelapp.models.RatesPageSettings;
public class RatesFragment extends Fragment {
public static final String TAG = RatesFragment.class.getSimpleName();
private ListView mRatesList;
private ApplicationContext mAppContext;
public static RatesFragment newInstance(ApplicationContext appContext) {
RatesFragment fragment = new RatesFragment();
fragment.mAppContext = appContext;
return fragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_rates, container, false);
RatesPageSettings ratesPageSettings = mAppContext
.getParsedApplicationSettings().getRatesPageSettings();
mRatesList = (ListView) view.findViewById(R.id.ratesFragmentListView);
mRatesList.setAdapter(new RatesListAdapter(mAppContext,
ratesPageSettings.getRoomRatesList()));
return view;
}
Public void llamado(View v){
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
intent.addCategory("android.intent.category.LAUNCHER");
intent.setData(Uri.parse("http://www.google.com"));
mContext.startActivity(intent);
}
}
Entonces como el método start activity no existe en los adapter, pensé en ves del poner el staractivity poner un código que me llame el método "llamado" que esta en mi Frament desde mi adapter
Es posible? como?