Android 4.2.2 Map Fragment Issue - android

I have a map with toolbar and a autocomplete search bar in coordinate layout . Everything works fine in Android version above 4.x but in Android 4.2.2 , shows only map . The toolbar and autocomplete textview is not showing .
Please help me to understand why this is happening .
Xml :
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<include
android:id="#+id/toolbar"
layout="#layout/activity_self_assigned_toolbar" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:id="#+id/custom_map_cross"
android:src="#drawable/icn_close"/>
<!--<Button-->
<!--android:id="#+id/search_button"-->
<!--android:layout_width="20dp"-->
<!--android:layout_weight="0.5"-->
<!--android:layout_height="40dp"-->
<!--android:layout_marginRight="5dp"-->
<!--android:layout_gravity="center"-->
<!--android:padding="5dp"-->
<!--android:background="#color/indigo_500"-->
<!--android:textColor="#android:color/white"-->
<!--android:text="Save" />-->
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
map.java :
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.custom_map_layout,container,false);
ButterKnife.inject(this,view);
// view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT));
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
// SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
// mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
// .getMap();
initialise();
initialiseListeners();
autoCompView.setAdapter(new GooglePlacesAutocompleteAdapter(getActivity(), R.layout.map_single_item));
autoCompView.setOnItemClickListener(this);
saveButton.setOnClickListener(this);
cancelButton.setOnClickListener(this);
return view;
}
private void initialise() {
// toolbar.setNavigationIcon(R.drawable.ic_keyboard_arrow_left_black_24dp);
activity = (AppCompatActivity) getActivity();
toolbar.setTitle("Address");
}
private void initialiseListeners() {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getActivity().onBackPressed();
}
});
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
View view1 = getActivity().getCurrentFocus();
if (view1 != null) {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view1.getWindowToken(), 0);
}
// and next place it, for exemple, on bottom right (as Google Maps app)
str = (String) parent.getItemAtPosition(position);
// Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
getLocationFromAddress(str);
if (latitude != null && longitude != null) {
LatLng latLng = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(latLng));
CameraPosition pos = CameraPosition.builder()
.target( latLng)
.zoom( 12f )
.bearing( 0.0f )
.tilt( 0.0f )
.build();
mMap.setMyLocationEnabled(true);
mMap.animateCamera( CameraUpdateFactory
.newCameraPosition( pos ), null );
}
}
public void getLocationFromAddress(String strAddress) {
Geocoder coder = new Geocoder(context);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress, 5);
if (address != null) {
Address location = address.get(0);
latitude = location.getLatitude();
longitude = location.getLongitude();
}
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.self_assignment_save_textview:
new generateCheckinsTask(context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case R.id.self_assignment_cancel_textview:
//
// getActivity().getSupportFragmentManager().popBackStack();
break;
}
}
private class generateCheckinsTask extends AsyncTask {
private Context context;
generateCheckinsTask(Context context) {
this.context = context;
}
#Override
protected Object doInBackground(Object[] params) {
return null;
}
#Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
Time time = new Time();
time.setToNow();
Fragment_Self_Assignment self_assignment = new Fragment_Self_Assignment();
self_assignment.updateAddress(str,latitude,longitude);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// if (materialDialog != null && materialDialog.isShowing()) {
// materialDialog.dismiss();
// }
getActivity().finish();
}
}, 500);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
}
#Override
public void onResume() {
Spannable actionBarTitle = new SpannableString("Add Place");
actionBarTitle.setSpan(
new ForegroundColorSpan(Color.WHITE),
0,
actionBarTitle.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if(((AppCompatActivity) getActivity()).getSupportActionBar() != null){
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(actionBarTitle);
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if(!imm.isAcceptingText()){
imm.hideSoftInputFromWindow(getView().getWindowToken(),0);
}
}
super.onResume();
}
#Override
public void onStart() {
super.onStart();
if (activity.getSupportActionBar().isShowing())
activity.getSupportActionBar().hide();
}
#Override
public void onStop() {
super.onStop();
if (!activity.getSupportActionBar().isShowing())
activity.getSupportActionBar().show();
}
public static ArrayList autocomplete(String input) {
ArrayList resultList = null;
HttpURLConnection conn = null;
StringBuilder jsonResults = new StringBuilder();
try {
StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
sb.append("?key=" + API_KEY);
// sb.append("&components=country:gr");
sb.append("&input=" + URLEncoder.encode(input, "utf8"));
URL url = new URL(sb.toString());
conn = (HttpURLConnection) url.openConnection();
InputStreamReader in = new InputStreamReader(conn.getInputStream());
// Load the results into a StringBuilder
int read;
char[] buff = new char[1024];
while ((read = in.read(buff)) != -1) {
jsonResults.append(buff, 0, read);
}
} catch (MalformedURLException e) {
Log.e(LOG_TAG, "Error processing Places API URL", e);
return resultList;
} catch (IOException e) {
Log.e(LOG_TAG, "Error connecting to Places API", e);
return resultList;
} finally {
if (conn != null) {
conn.disconnect();
}
}
try {
// Create a JSON object hierarchy from the results
JSONObject jsonObj = new JSONObject(jsonResults.toString());
JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");
// Extract the Place descriptions from the results
resultList = new ArrayList(predsJsonArray.length());
for (int i = 0; i < predsJsonArray.length(); i++) {
System.out.println(predsJsonArray.getJSONObject(i).getString("description"));
System.out.println("============================================================");
resultList.add(predsJsonArray.getJSONObject(i).getString("description"));
}
} catch (JSONException e) {
Log.e(LOG_TAG, "Cannot process JSON results", e);
}
return resultList;
}
}
ISSUE : image(4.2.2 version):
image of same code on greater version (code working fine):

check this one
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:id="#+id/custom_map_cross"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:src="#drawable/pick_ticket_bg_large" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>

Your MapFragment is overlaping your ToolBar and autocomplete search bar, keep them above MapFragment.
Try this.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/toolbar"
layout="#layout/activity_self_assigned_toolbar" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:id="#+id/custom_map_cross"
android:src="#drawable/icn_close"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

Related

array adapter returns null

i have two adapters and a fragment, and i want to display feeds on two views, one bottom and one recycler view. Although the Json was working with a list adapter. its not working with the recycler view.
here is the main fragment
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardExpand;
import it.gmariotti.cardslib.library.internal.CardHeader;
import it.gmariotti.cardslib.library.view.CardViewNative;
import jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout;
public class FeedFragmentAlternative extends Fragment{
private static final String TAG = FeedFragmentAlternative.class.getSimpleName();
private String URL_FEED = "http://api.androidhive.info/feed/feed.json";
private WaveSwipeRefreshLayout mWaveSwipeRefresh;
int duration = 200;
private List<FeedItem> FeedItems;
public static FeedFragmentAlternative newInstance(){
FeedFragmentAlternative feedFragmentAlternative = new FeedFragmentAlternative();
return feedFragmentAlternative;
}
private void refresh(){
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mWaveSwipeRefresh.setRefreshing(false);
}
},3000);
}
private ExpandablePager pager;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.feed_activity_alternate, container, false);
final List<FeedItem> myFeedList = new ArrayList<>();
final FeedExpandableAdapter adapter = new FeedExpandableAdapter(myFeedList);
pager = (ExpandablePager) getActivity().findViewById(R.id.bottom_feed_container);
pager.setAdapter(adapter);
pager.setOnSliderStateChangeListener(new OnSliderStateChangeListener() {
#Override
public void onStateChanged(View page, int index, int state) {
toggleContent(page, state, duration);
}
#Override
public void onPageChanged(View page, int index, int state) {
toggleContent(page, state, 0);
}
});
final RecyclerView mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feeds_list_recycler_view);
mRecyclerView.setHasFixedSize(true);
final FeedGridAdapter a = new FeedGridAdapter(myFeedList);
a.setListener(new OnItemClickedListener() {
#Override
public void onItemClicked(int index) {
pager.setCurrentItem(index, false);
pager.animateToState(ExpandablePager.STATE_EXPANDED);
}
});
mWaveSwipeRefresh = (WaveSwipeRefreshLayout)view.findViewById(R.id.feed_wave_swipe_layout_refresh_alternate);
mWaveSwipeRefresh.setColorSchemeColors(Color.WHITE, Color.GREEN);
mWaveSwipeRefresh.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
pager.setAdapter(adapter);
mRecyclerView.setAdapter(a);
FeedFragmentAlternative.newInstance();
refresh();
}
});
mWaveSwipeRefresh.setWaveColor(Color.parseColor("#80C5EFF7"));
mWaveSwipeRefresh.setMaxDropHeight((int)(mWaveSwipeRefresh.getHeight() * 0.9));
mRecyclerView.setAdapter(a);
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Cache.Entry entry = cache.get(URL_FEED);
if (entry != null){
try {
String data = new String (entry.data, "UTF-8");
try {
parseJsonFeed(new JSONObject(data));
} catch (JSONException e){
e.printStackTrace();
}
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
} else {
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET,
URL_FEED, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response:" + response.toString());
if (response != null){
parseJsonFeed(response);
}
}
},new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "ERROR:" + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jsonReq);
}
return view;
}
private void toggleContent(final View page, final int state, int duration){
final int headerHeight = (int) getResources().getDimension(R.dimen.header_height);
if (page != null){
ValueAnimator animator = state == ExpandablePager.STATE_EXPANDED ? ValueAnimator.ofFloat(1,0): ValueAnimator.ofFloat(0,1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
page.findViewById(R.id.profile_name_header).setTranslationY(25 * (1 - ((Float) animation.getAnimatedValue())));
page.findViewById(R.id.profile_name_header).setTranslationX(-headerHeight * (1 - ((Float)animation.getAnimatedValue())));
page.findViewById(R.id.feed_time_stamp_header).setAlpha(((Float)animation.getAnimatedValue()));
page.findViewById(R.id.profile_pic_header_image).setAlpha(((Float)animation.getAnimatedValue()));
page.findViewById(R.id.feed_like_bottom_sheet).setAlpha(((Float) animation.getAnimatedValue()));
}
});
animator.setDuration((long)(duration * 5));
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
}
private void parseJsonFeed(JSONObject response){
try {
JSONArray feedArray = response.getJSONArray("feed");
for (int i = 0;i < feedArray.length(); i++){
JSONObject feedObj = (JSONObject) feedArray.get(i);
FeedItem item = new FeedItem();
item.setId(feedObj.getInt("id"));
item.setName(feedObj.getString("name"));
String image = feedObj.isNull("image")? null : feedObj
.getString("image");
item.setImge(image);
item.setStatus(feedObj.getString("status"));
item.setProfilePic(feedObj.getString("profilePic"));
item.setTimeStamp(feedObj.getString("timeStamp"));
String feedUrl = feedObj.isNull("url")? null : feedObj
.getString("url");
item.setUrl(feedUrl);
FeedItems.add(item);
}
} catch (JSONException e){
e.printStackTrace();
}
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initCards();
}
private void initCards(){
init_standard_header_with_expandcollapse_button();
}
private void init_standard_header_with_expandcollapse_button(){
Card card = new Card(getActivity());
CardHeader header = new CardHeader(getActivity());
header.setButtonExpandVisible(true);
card.addCardHeader(header);
CardExpand expand = new CardExpand(getActivity());
expand.setTitle("expanded");
CardViewNative cardViewNative = (CardViewNative) getActivity().findViewById(R.id.feed_card_style);
cardViewNative.setCard(card);
}
}
the grid adapter is as follows
public class FeedGridAdapter extends RecyclerView.Adapter<FeedGridAdapter.ViewHolder> {
private OnItemClickedListener listener;
private List<FeedItem> mFeedItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public static class ViewHolder extends RecyclerView.ViewHolder{
public LoginTextView ProfileNameCell;
public LoginTextView FeedTimesStampCell;
public NetworkImageView ProfilepicCell;
public LoginTextView FeedStatusMgsCell;
public FeedImageView FeedImageViewCell;
public ViewGroup container;
public ViewHolder(RelativeLayout v){
super(v);
container = v;
ProfileNameCell = (LoginTextView) v.findViewById(R.id.client_name_alternate_cell);
FeedTimesStampCell = (LoginTextView) v.findViewById(R.id.time_stamp_alternate_cell);
ProfilepicCell = (NetworkImageView) v.findViewById(R.id.profile_pic_alternate_cell);
FeedStatusMgsCell = (LoginTextView) v.findViewById(R.id.txtStatusMgs_alternate);
FeedImageViewCell = (FeedImageView) v.findViewById(R.id.feedImage1_alternate);
}
}
public FeedGridAdapter(List<FeedItem> feedItems){mFeedItems = feedItems;}
#Override
public FeedGridAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RelativeLayout v = (RelativeLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.feed_card_alternate, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.ProfileNameCell.setText(mFeedItems.get(position).getName());
CharSequence timeStampCell = DateUtils.getRelativeTimeSpanString(
Long.parseLong(mFeedItems.get(position).getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
holder.FeedTimesStampCell.setText(timeStampCell);
if (!TextUtils.isEmpty(mFeedItems.get(position).getStatus())){
holder.FeedStatusMgsCell.setText(mFeedItems.get(position).getStatus());
holder.FeedStatusMgsCell.setVisibility(View.VISIBLE);
} else {
holder.FeedStatusMgsCell.setVisibility(View.GONE);
}
holder.ProfilepicCell.setImageUrl(mFeedItems.get(position).getImge(), imageLoader);
if (mFeedItems.get(position).getImge() != null){
holder.FeedImageViewCell.setImageUrl(mFeedItems.get(position).getImge(), imageLoader);
holder.FeedImageViewCell.setVisibility(View.VISIBLE);
holder.FeedImageViewCell
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
holder.FeedImageViewCell.setVisibility(View.GONE);
}
holder.container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listener != null)
listener.onItemClicked(holder.getAdapterPosition());
}
});
}
#Override
public int getItemCount() {
return mFeedItems.size();
}
public void setListener(OnItemClickedListener listener){this.listener = listener;}
}
and the expandable fragment is
public class FeedExpandableAdapter extends ExpandablePagerAdapter<FeedItem> {
public FeedExpandableAdapter(List<FeedItem> items){super(items);}
private LayoutInflater inflater;
private Activity activity;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
#Override
public Object instantiateItem(ViewGroup container, int position) {
final ViewGroup rootView = (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.feed_page_alternative, container, false);
if (inflater == null)
inflater = (LayoutInflater)activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
LoginTextView name = (LoginTextView) rootView.findViewById(R.id.profile_name_header);
LoginTextView timestamp = (LoginTextView) rootView.findViewById(R.id.feed_time_stamp_header);
NetworkImageView profilepic = (NetworkImageView) rootView.findViewById(R.id.profile_pic_header_image);
FeedImageView feedImageView = (FeedImageView) rootView.findViewById(R.id.feed_main_image_bottom_sheet);
LoginTextView statusMgs = (LoginTextView) rootView.findViewById(R.id.body_bottom_panel_feed);
name.setText(items.get(position).getName());
CharSequence timeofStamp = DateUtils.getRelativeTimeSpanString(
Long.parseLong(items.get(position).getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
timestamp.setText(timeofStamp);
if (!TextUtils.isEmpty(items.get(position).getStatus())){
statusMgs.setText(items.get(position).getStatus());
statusMgs.setVisibility(View.VISIBLE);
} else {
statusMgs.setVisibility(View.GONE);
}
profilepic.setImageUrl(items.get(position).getProfilePic(), imageLoader);
if (items.get(position).getImge() != null) {
feedImageView.setImageUrl(items.get(position).getImge(), imageLoader);
feedImageView.setVisibility(View.VISIBLE);
feedImageView
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
feedImageView.setVisibility(View.GONE);
}
return attach(container, rootView, position);
}
}
the error shown is like this -
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.telenav.expandablepager.ExpandablePager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
at com.evolustudios.askin.askin.src.fragments.FeedFragmentAlternative.onCreateView(FeedFragmentAlternative.java:86)
can anyone tell me why its returning null?
its possible duplicate, but i cannot figure out why its returning null
xml - feed_card_alternate
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="350dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<it.gmariotti.cardslib.library.view.CardViewNative
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_card_style"
style="#style/card_external">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame_list_card_item_alternate"
android:background="#drawable/cardpanel"
android:paddingTop="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:id="#+id/feed_top_panel_alternate"
android:paddingBottom="25dp">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/profile_pic_alternate_cell"
android:scaleType="fitCenter"
android:paddingTop="15dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="15dp">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/client_name_alternate_cell"
android:textSize="15dp"
android:textStyle="bold"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/time_stamp_alternate_cell"
android:textColor="#color/timestamp"
android:textSize="13dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/feed_other_content_alternate"
android:layout_below="#+id/feed_top_panel_alternate">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtStatusMgs_alternate"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="13dp" />
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtUrl_alternate"
android:linksClickable="true"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/link" />
<com.evolustudios.askin.askin.src.Utils.FeedImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/feedImage1_alternate"
android:background="#80FFFFFF"
android:scaleType="fitXY"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</it.gmariotti.cardslib.library.view.CardViewNative>
feed_activity_alternate.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_wave_swipe_layout_refresh_alternate">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feeds_list_recycler_view"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:scrollbars="vertical"
tools:listitem="#layout/feed_item_list_new">
</android.support.v7.widget.RecyclerView>
<com.telenav.expandablepager.ExpandablePager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bottom_feed_container"
android:layout_gravity="bottom"
app:animation_duration="200"
app:collapsed_height="#dimen/header_height"/>
</jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout>
feed_page_alternative
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#color/pumice">
<include
layout="#layout/feed_header_layout"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250sp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="10dp"
android:id="#+id/feed_bottom_panel_first_container">
<com.evolustudios.askin.askin.src.Utils.FeedImageView
android:layout_width="270sp"
android:layout_height="match_parent"
android:background="#color/edward"
android:id="#+id/feed_main_image_bottom_sheet"
android:scaleType="fitCenter"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scrollbars="none">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_extra_iamge_list_view_bootom_panel">
</ListView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/feed_bottom_panel_second_container"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_very_satisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:src="#drawable/ic_sentiment_satisfied_black_24dp"
android:scaleType="fitCenter"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_neutral_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_dissatisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_very_dissatisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/feed_bottom_panel_third_container"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/very_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/neutral_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/not_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/very_not_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/body_bottom_panel_feed"
android:text="Body"
android:textSize="20dp"/>
</ScrollView>
Change,
pager = (ExpandablePager) getActivity().findViewById(R.id.bottom_feed_container);
to
pager = (ExpandablePager) view.findViewById(R.id.bottom_feed_container);
Also change,
final RecyclerView mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feeds_list_recycler_view);
to
final RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.feeds_list_recycler_view);

I can't see change on Android Coordinator Layout

I can't see correct data on my Coordinator Layout: I mean, my layout seems correctly set and my java class is correct too.
But when I launch my application I don't see error but my activity have TextView, Image and WebView not initialized with passed data.
I tried to inflate all content with traditional
(TextView) findViewById(R.id.my_id) and with butterknife.ButterKnife library, same result.
Here my activity
public class EventDetailsActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleMap.OnMapClickListener {
private long eventID;
private String eventTitle;
private String eventDesc;
private String eventDate;
private String eventTime;
private String eventImageUrl;
private String eventAddress;
private Double lat;
private Double lng;
private int maxBookings;
#InjectView(R.id.event_title) TextView eventTitleTv;
#InjectView(R.id.event_address) TextView eventAddressTv;
#InjectView(R.id.event_start_date) TextView eventDateTv;
#InjectView(R.id.event_start_time) TextView eventTimeTv;
#InjectView(R.id.event_image) ImageView imageEventView;
#InjectView(R.id.map_address) TextView evetMapAddress;
#InjectView(R.id.event_desc) WebView mWebView;
#InjectView(R.id.toolbar) Toolbar toolbar;
#InjectView(R.id.collapsing_toolbar) CollapsingToolbarLayout collapsingToolbarLayout;
#InjectView(R.id.btnJoin) AppCompatButton btnJoin;
#InjectView(R.id.open_map_button) FloatingActionButton openMapButton;
private MapFragment googleMap;
private GoogleMap map;
private Event event;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivityTransitions();
setContentView(R.layout.event_details_activity);
ButterKnife.inject(this);
btnJoin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showDialogPlus();
}
});
openMapButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openMapDetail();
}
});
try {
inizializeToolbar();
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
event = extras == null ? null : (Event) extras.getSerializable(Const.EVENT_OBJECT);
} else {
event = (Event) savedInstanceState.getSerializable(Const.EVENT_OBJECT);
}
eventTitle = event.getEventName();
eventDesc = event.getEventContent();
eventDate = event.getEventStartDate();
eventTime = event.getEventStartTime();
eventImageUrl = event.getEventImageUrl();
lat = event.getLocationLatitude();
lng = event.getLocationLongitude();
eventAddress = event.getLocationAddress();
eventID = event.getEventId();
maxBookings = 10;
Log.d("EVENT", "__event title " + eventTitle);
Log.d("EVENT", "__event eventDesc " + eventDesc);
Log.d("EVENT", "__event eventDate " + eventDate);
Log.d("EVENT", "__event eventTime " + eventTime);
Log.d("EVENT", "__event eventImageUrl " + eventImageUrl);
Log.d("EVENT", "__event lat " + lat);
Log.d("EVENT", "__event lng " + lng);
Log.d("EVENT", "__event eventAddress " + eventAddress);
Log.d("EVENT", "__event eventTitle " + eventTitle);
Log.d("EVENT", "__event evv name " + event.getEventName());
initializeMap();
loadImage();
loadTextViews();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initActivityTransitions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide transition = new Slide();
transition.excludeTarget(android.R.id.statusBarBackground, true);
getWindow().setEnterTransition(transition);
getWindow().setReturnTransition(transition);
}
}
private void inizializeToolbar() {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
collapsingToolbarLayout.setTitle(eventTitle);
collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);
collapsingToolbarLayout.setExpandedTitleColor(Color.TRANSPARENT);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
private void loadTextViews(){
eventTitleTv.setText("TITOLO DELL'EVENTO");
eventAddressTv.setText(eventAddress);
evetMapAddress.setText(eventAddress + " -> ");
setEventDesc();
eventDateTv.setText(Utils.getDateFromString(eventDate));
eventTimeTv.setText(Utils.getTimeFromString(eventTime));
}
private void loadImage(){
final ProgressBar progressView = (ProgressBar) findViewById(R.id.loader);
progressView.getIndeterminateDrawable().setColorFilter(getApplicationContext().getResources().getColor(R.color.ColorPrimary), android.graphics.PorterDuff.Mode.MULTIPLY);
Picasso.with(getApplicationContext())
.load(eventImageUrl)
.fit().centerCrop()
.placeholder(R.drawable.event_placeholder_grey_2)
.into(imageEventView, new Callback() {
#Override
public void onSuccess() {
progressView.setVisibility(View.GONE);
}
#Override
public void onError() {
progressView.setVisibility(View.GONE);
}
});
}
private void showDialogPlus() {
Holder holder = new ViewHolder(R.layout.event_prenotation);
OnClickListener clickListener = new OnClickListener() {
#Override
public void onClick(DialogPlus dialog, View view) {
Spinner mySpinner=(Spinner) dialog.getHolderView().findViewById(R.id.spinner);
String bookValue = mySpinner.getSelectedItem().toString();;
int numberPerson = Integer.parseInt(bookValue);
switch (view.getId()) {
case R.id.btnJoin:
Intent intent = new Intent(getApplicationContext(), ConfirmPrenotationActivity.class);
Bundle bun = new Bundle();
bun.putInt(Const.NUMBER_PRENOT, numberPerson);
bun.putString(Const.EVENT_TITLE, eventTitle);
bun.putLong(Const.EVENT_ID, eventID);
bun.putSerializable(Const.EVENT_OBJECT, event);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(bun);
getApplicationContext().startActivity(intent);
break;
}
//dialog.dismiss();
}
};
OnItemClickListener itemClickListener = new OnItemClickListener() {
#Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
//TextView textView = (TextView) view.findViewById(R.id.text_view);
//String clickedAppName = textView.getText().toString();
// dialog.dismiss();
// Toast.makeText(MainActivity.this, clickedAppName + " clicked", Toast.LENGTH_LONG).show();
}
};
OnDismissListener dismissListener = new OnDismissListener() {
#Override
public void onDismiss(DialogPlus dialog) {
// Toast.makeText(MainActivity.this, "dismiss listener invoked!", Toast.LENGTH_SHORT).show();
}
};
OnCancelListener cancelListener = new OnCancelListener() {
#Override
public void onCancel(DialogPlus dialog) {
// Toast.makeText(MainActivity.this, "cancel listener invoked!", Toast.LENGTH_SHORT).show();
}
};
final DialogPlus dialog = DialogPlus.newDialog(this)
.setContentHolder(holder)
.setCancelable(true)
.setGravity(Gravity.BOTTOM)
.setOnClickListener(clickListener)
.setOnItemClickListener(new OnItemClickListener() {
#Override public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
Log.d("DialogPlus", "onItemClick() called with: " + "item = [" +
item + "], position = [" + position + "]");
}
})
.setOnDismissListener(dismissListener)
//.setExpanded(expanded)
//.setContentWidth(800)
.setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
.setOnCancelListener(cancelListener)
.setOverlayBackgroundResource(android.R.color.transparent)
//.setContentBackgroundResource(R.drawable.corner_background)
//.setOutMostMargin(0, 100, 0, 0)
.create();
Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner);
initializeSpinner(spinner);
dialog.show();
}
public void initializeSpinner(Spinner spin){
ArrayList<String> options = new ArrayList<String>();
for(int i=1; i<= maxBookings; i++){
options.add(""+i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_style, options) {
public View getView(int position, View convertView,ViewGroup parent) {
View v = super.getView(position, convertView, parent);
((TextView) v).setTextSize(18);
return v;
}
public View getDropDownView(int position, View convertView,ViewGroup parent) {
View v = super.getDropDownView(position, convertView,parent);
//((TextView) v).setGravity(Gravity.CENTER);
return v;
}
};
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
}
public void setEventDesc(){
mWebView.setBackgroundColor(Color.TRANSPARENT);
StringBuilder sb = new StringBuilder();
sb.append("<html><body>");
sb.append("<p align=\"justify\">");
sb.append(eventDesc);
sb.append("</p>");
sb.append("</body></html>");
//mWebView.loadData(sb.toString(), "text/html", "utf-8");
mWebView.loadData(sb.toString(), "text/html; charset=utf-8", "utf-8");
}
#TargetApi(Build.VERSION_CODES.M)
public void initializeMap() {
if (googleMap == null) {
googleMap = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
googleMap.getMapAsync(this);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_event_details, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.share_button:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, getEventInfoToShare());
startActivity(Intent.createChooser(shareIntent, "Share link using"));
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
}
}
private String getEventInfoToShare(){
StringBuilder infoEvent = new StringBuilder();
infoEvent.append("Ciao, vorrei consigliarti un evento :-)");
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventTitle);
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventAddress);
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventDesc.substring(0, Math.min(eventDesc.length(), 200)));
infoEvent.append("...continua");
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append("Visita -> www.dayroma.it");
return infoEvent.toString();
}
#Override
public void onBackPressed() {
finish();
super.onBackPressed();
}
#Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setOnMapClickListener(this);
googleMap.getUiSettings().setScrollGesturesEnabled(false);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 15.0f));
map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng))
.title(eventTitle));
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
openMapDetail();
return true;
}
});
}
public void openMapDetail(){
Intent i = new Intent(getApplicationContext(), MapsDetailActivity.class);
Bundle bun = new Bundle();
bun.putDouble(Const.EVENT_LAT, lat);
bun.putDouble(Const.EVENT_LONG, lng);
bun.putString(Const.EVENT_TITLE, eventTitle);
bun.putString(Const.EVENT_ADDRESS, eventAddress);
bun.putString(Const.EVENT_IMG_LINK, eventImageUrl);
bun.putSerializable(Const.EVENT_OBJECT, event);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtras(bun);
getApplicationContext().startActivity(i);
}
#Override
public void onMapClick(LatLng latLng) {
openMapDetail();
}
}
And here the layout:
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/image_event_detail_height"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/ColorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true"
>
<util.SquareImageView
android:id="#+id/event_image"
android:layout_width="match_parent"
android:layout_height="#dimen/image_event_detail_height"
android:maxHeight="#dimen/image_event_detail_height"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!--<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ProgressBar
android:id="#+id/loader"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_gravity="center"
android:indeterminate="true"
android:layout_centerInParent="true"
/>
</RelativeLayout>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#drawable/google_cards_background_bottom"
android:gravity="left"
android:orientation="vertical" >
<!-- Titolo Evento -->
<TextView
android:id="#+id/event_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:text="Eat at Joe"
android:textColor="#color/ColorPrimary"
android:textSize="18sp"
/>
<!-- indirizzo -->
<TextView
android:id="#+id/event_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="9dp"
android:layout_marginBottom="1dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/ic_position_black_18dp"
android:drawablePadding="2dip"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="left"
android:orientation="horizontal" >
<!-- data inizio evento-->
<TextView
android:id="#+id/event_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/calendar_black_18dp"
android:drawablePadding="2dip"
/>
<!-- ora inizio evento-->
<TextView
android:id="#+id/event_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="3dp"
android:layout_marginBottom="20dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/clock_18dp"
android:drawablePadding="2dip"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
</LinearLayout>
<!-- DETTAGLI -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/rounded_shape"
>
<TextView
android:id="#+id/event_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="3dp"
android:background="#android:color/transparent"
android:text="Dettagli"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="17sp"
android:gravity="center"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >
<WebView
android:id="#+id/event_desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hardwareAccelerated="true"
/>
</ScrollView>
</LinearLayout>
<!-- FINE DETTAGLI -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:foreground="#color/dark_trasparent"
>
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="#dimen/map_height"
map:cameraTargetLat="41.890122"
map:cameraTargetLng="12.494248"
map:cameraTilt="30"
map:cameraZoom="15"
tools:ignore="MissingPrefix"
android:clickable="false"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- Maps Address -->
<TextView
android:id="#+id/map_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="22dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#android:color/transparent"
android:text="via Cristoforo Colombo 24"
android:textColor="#color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/ic_position_white_18dp"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/open_map_button"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="#color/ColorPrimary"
android:tint="#color/cpb_grey"
android:src="#drawable/navigation_black_24dp"
style="#style/floatButtonStyle"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true"
android:background="#00ffffff"
>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btnJoin"
android:background="#drawable/rounded_button_red"
android:layout_width="fill_parent"
android:textSize="17dp"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_height="#dimen/fixed_bottom_button_height"
android:layout_margin="10dp"
android:layout_centerHorizontal="true"
android:text="#string/join_event"
/>
</LinearLayout>
</RelativeLayout>
It seems a simple problem but I've never had like this before: here a screenshot of my activity, it should be visualize an event details.
Screenshot Activity
This activity is opened when a user click on an event and is fill with event data: data are correctly set because I can see all from log.
I really don't understand why TextViews, ImageView and other element are not filled with data.
Thank you for help
I can't see any closing tag for Coordinator layout in your xml file. If you haven't missed it in question then probably that is the reason for this strange behavior.
Add this at the end of your xml code and things should work better.
</android.support.design.widget.CoordinatorLayout>
Or, if that is just the mistake in question then please update your question. Whatever it is do let me know.

Add an image for Android marker info window

I'm making an android app. In this app, there are markers of some hotels and when user click on the marker info window appears and it should be like following image. (This is a web application)
I have a list view in my navigation drawer fragment and map fragment has the markers.
This is my code before I try to load image for the info window in MainActivity.java.
// Load Hotels
private class GetHotelTask extends AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... data) {
String identifier = data[0];
// Toast.makeText(getContext(), "Manuli "+identifier, Toast.LENGTH_LONG ).show();
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://api.ayubo.lk/android/retrievehotels");
HttpResponse response = null;
String responseStr = null;
try {
//add data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("long", data[0]));
nameValuePairs.add(new BasicNameValuePair("lat", data[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//execute http post
response = httpclient.execute(httppost);
responseStr = EntityUtils.toString(response.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return responseStr;
}
protected void onPostExecute(String result) {
try {
JSONArray jObj = new JSONArray(result);
for(int a=0;a<jObj.length();a++){
JSONArray obj= (JSONArray) jObj.get(a);
Log.i("json", obj.get(3).toString());
Marker marker = GoogleMapsFragment.map.addMarker(new MarkerOptions()
.position(new LatLng( Double.valueOf(obj.get(3).toString()), Double.valueOf(obj.get(2).toString())))
.title(obj.get(1).toString()+" | simple Price : "+obj.get(4).toString())
.snippet(obj.get(5).toString())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_hotel)));
hotelMarkers.add(marker);
}
LatLng latLng = new LatLng(Double.valueOf(latitude),Double.valueOf(longtitude));
GoogleMapsFragment.map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
GoogleMapsFragment.map.animateCamera(CameraUpdateFactory.zoomTo(15));
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
}
}
Here is the listview call of hotels inside MainActivity.java.
// Hotels
case 0:
if (A == 0){
Bundle bundle = new Bundle();
bundle.putString("restaurants", "Default");
fragmentObj = new GoogleMapsFragment();
fragmentObj.setArguments(bundle);
if (!sclItems.contains(0)){
new GetHotelTask().execute(longtitude, latitude);
sclItems.add(0);
}else {
removeHotels();
sclItems.remove((Integer)0);
}
A = 1;
}else {
if (!sclItems.contains(0)){
new GetHotelTask().execute(longtitude, latitude);
sclItems.add(0);
}else {
removeHotels();
sclItems.remove((Integer)0);
}
}
break;
I've tried adding info_window_layout.xml and here is the code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="#drawable/ic_prof"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"/>
</LinearLayout>
</LinearLayout>
But, I cannot load my info window like in the image. I've tried several solutions including this and any of that didn't give me a solution.
Can someone please help me with this?
Thanks in advance. :)
Error -
Figured it out finally. :D
Changed the info_window_layout.xml like this.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000" >
<LinearLayout
android:id="#+id/text_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/markerImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
Then added a new class called, ManiInfoAdapter.java
class MapInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private LayoutInflater inflater;
private Context context;
public MapInfoWindowAdapter(Context context){
inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
this.context = context;
}
#Override
public View getInfoWindow(Marker marker) {
// Getting view from the layout file
View v = inflater.inflate(R.layout.info_window_layout, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView address = (TextView) v.findViewById(R.id.distance);
address.setText(marker.getSnippet());
ImageView iv = (ImageView) v.findViewById(R.id.markerImage);
iv.setImageResource(R.drawable.ic_attraction1);
return v;
}
#Override
public View getInfoContents(Marker marker) {
return null;
}
}
Now working as expected. :)
Try this code :
Marker kiel=FragmentLeft.map.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(p.getLatitude()), Double.parseDouble(p.getLongitude())))
.title(p.getEventName()).snippet(getLocationStringAddress(new LatLng(Double.parseDouble(p.getLatitude()), Double.parseDouble(p.getLongitude()))))
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_set_marker)));
markers.put(kiel.getId(),"http://"+strPhoto);
kiel.setInfoWindowAnchor(1.95f,0.0f);
hMarker.put(kiel,p);
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker arg0) {
View myContentView = flipscreen.this.getLayoutInflater().inflate(R.layout.custommarker, null);
TextView tvTitle = ((TextView) myContentView.findViewById(R.id.title));
tvTitle.setText(arg0.getTitle());
TextView tvSnippet = ((TextView) myContentView.findViewById(R.id.snippet));
tvSnippet.setText(arg0.getSnippet());
ImageView imgMarkerImage=(ImageView)myContentView.findViewById(R.id.imgMarkerImage);
System.out.println("List of Event Photos = " + strPhoto);
Picasso.with(flipscreen.this).load(markers.get(arg0.getId())).into(imgMarkerImage);
return myContentView;
}
#Override
public View getInfoContents(Marker marker) {
return null;
}
});
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
Iterator myVeryOwnIterator = hMarker.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
Marker key=(Marker)myVeryOwnIterator.next();
if(marker.getId().equals(key.getId())){
Event value=(Event)hMarker.get(key);
Activity_Event_Details.setEventDetails(value);
startActivity(new Intent(flipscreen.this,Activity_Event_Details.class));
}
}
}
});
I have tried to do the same for my app. I couldn't load images into the marker as I wanted.
So what I did was.
Created an xml layout maps_info_window_blue
I included into my map layout.
<fragment
android:id="#+id/map_booking_frg"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/center_marker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/shadowView"
android:layout_centerHorizontal="true"
android:src="#drawable/marker_start" />
<include layout="#layout/maps_info_window_blue"
android:id="#+id/rl_info_window_blue"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#+id/shadowView"
android:layout_height="wrap_content"/>
<View
android:id="#+id/shadowView"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="#color/transparent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible" />
For me the requirement was to have the marker info window in the center. You can set it where ever you want.
In order to give the illusion of a marker, I always set LatLng which I want to be the center of the map (CameraPosition target is set to the LatLng I want)
Try using info window adapter. This may help you i think.
mMap.setInfoWindowAdapter(setMarkerWindow());
private GoogleMap.InfoWindowAdapter setMarkerWindow() {
return new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
View myContentView = getLayoutInflater().inflate(
R.layout.map_info_window, null);
myContentView.setBackgroundColor(Color.TRANSPARENT);
TextView tvTitle = ((TextView) myContentView
.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
......
return myContentView;
}
#Override
public View getInfoContents(Marker marker) {
return null;
}
};
}

How to loop execution of AsyncTask with an array of params

I'm new in Android programming.
I created classes of web objects each class has 3 RSS URLs to be parsed. I loop an array of this objects to operate on each one the AsyncTask Executer. Every time I do that different errors appear and the UI freezes. I can't find what's wrong. Then I use custom adapter to display the UI but program don't even reach to that code. Please help me finding what's wrong with my code. I tried everything I had in mind.
I loop it in the main thread like this:
public class MainActivity extends Activity
{
ArrayList <WebPage> wpObjects;
ListView lv;
int threadIsFinishedcounter=0;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.listView1);
WebPage ynet= new WebPage(R.drawable.ynet, "http://www.ynet.co.il/Integration/StoryRss2.xml","http://www.ynet.co.il/Integration/StoryRss6.xml","http://www.ynet.co.il/Integration/StoryRss3.xml");
WebPage walla=new WebPage(R.drawable.walla, "http://rss.walla.co.il/?w=/1/0/12/#rss.e","http://rss.walla.co.il/?w=/2/0/12/#rss.e","http://rss.walla.co.il/?w=/3/0/12/#rss.e");
WebPage nrg= new WebPage(R.drawable.nrg, "http://rss.nrg.co.il/news/","http://rss.nrg.co.il/finance","http://rss.nrg.co.il/sport");
wpObjects=new ArrayList<WebPage>();
wpObjects.add(ynet);
wpObjects.add(walla);
wpObjects.add(nrg);
for(WebPage item:wpObjects)
{
//new getParseData(wpObjects.indexOf(item)).execute(item.getUrls());
new getParseData(wpObjects.indexOf(item)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, item.getUrls());
}
if(threadIsFinishedcounter==wpObjects.size())
{
MyCostumedAdapter adapter=new MyCostumedAdapter(MainActivity.this, wpObjects);
lv.setAdapter(adapter);
if(threadIsFinishedcounter==wpObjects.size())
}
}
The AsyncTask class:
class getParseData extends AsyncTask<String,Void, Collecter>
{
int indexofwp;
public getParseData(int indexofwp) {
super();
this.indexofwp = indexofwp;
}
protected Collecter doInBackground(String... params) {
Collecter col = new Collecter() ;
ArrayList<String> allResult = new ArrayList<String>();
ArrayList<String> Titles = new ArrayList<String>();
for (int y = 0; y < params.length; y++) {
Titles.clear();
allResult.clear();
col.yIndex = y;
String urlString = params[y];
try {
URL url = new URL(urlString);
XmlPullParserFactory factory = XmlPullParserFactory
.newInstance();
XmlPullParser parser = factory.newPullParser();
InputStream is = url.openStream();
parser.setInput(is, null);
boolean inItemTag = false;
boolean inTitleTag = false;
String TagName;
int EventType = parser.getEventType();
while (EventType != XmlPullParser.END_DOCUMENT) {
Log.i("im in while loop of parser", "");
if (EventType == XmlPullParser.START_TAG) {
TagName = parser.getName();
if (inItemTag) {
if (TagName.equals("title"))
inTitleTag = true;
} else// !item
{
if (TagName.equals("item"))
inItemTag = true;
}
}
if (EventType == XmlPullParser.TEXT) {
if (inTitleTag) {
Titles.add(parser.getText());// AD THE TITLE
inTitleTag = false;
}
}
if (EventType == XmlPullParser.END_TAG) {
TagName = parser.getName();
if (TagName.equals("item"))
inItemTag = false;
}
EventType = parser.next();
Log.i("im after parser.next", "");
}// end while of parsing loop
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("EXEPTION******************",
"MalformedURLException*********");
} catch (XmlPullParserException e) {
e.printStackTrace();
Log.i("EXEPTION******************",
"XmlPullParserException*********");
} catch (IOException s) {
s.printStackTrace();
Log.i("IOException***************************", "");
}
synchronized (col) {
if (col.yIndex == 0) {
col.news.addAll(Titles);
col.rssRsult.add(col.news);
}
if (col.yIndex == 1) {
col.economy.addAll(Titles);
col.economy.size()+"");
col.rssRsult.add(col.economy);
}
if (col.yIndex == 2) {
col.sports.addAll(Titles);
col.sports.size()+"");
col.rssRsult.add(col.sports);
}
}
}// end of y loop
return col;
}
#Override
protected void onPreExecute()
{
if(threadIsFinishedcounter==wpObjects.size())
threadIsFinishedcounter=0;
}
#Override
protected void onPostExecute(Collecter coll)
{
if(indexofwp<wpObjects.size())
{
wpObjects.get(indexofwp).NewsTitles.addAll(coll.rssRsult.get(0));
wpObjects.get(indexofwp).EconomicsTitles.addAll(coll.rssRsult.get(1))
wpObjects.get(indexofwp).SportssTitles.addAll(coll.rssRsult.get(2));
threadIsFinishedcounter++;
}
I thought maybe my custom adapter is wrong but didn't find anything wrong:
public class MyCostumedAdapter extends BaseAdapter
{
Context context;
ArrayList<WebPage> wp;
public MyCostumedAdapter(Context context , ArrayList<WebPage> wp)
{
super();
this.context = context;
this.wp=wp;
}
#Override
public int getCount()
{
return wp.size();
}
#Override
public Object getItem(int position)
{
return wp.get(position);
}
#Override
public long getItemId(int position)
{
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View rowView;
if(convertView==null)
{
LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView= inflater.inflate(R.layout.lvlayout, null);
}
else
{
final WebPage currentwp=wp.get(position);
rowView=convertView;
ImageView imag=(ImageView)rowView.findViewById(R.id.imageView1);
imag.setImageResource(currentwp.getIcon());
Button newsButton=(Button)rowView.findViewById(R.id.AllnewsButton);
newsButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(context,NewHeadlines.class);
intent.putExtra("newsbutton",currentwp.getNewsTitles());//to pass information to next activity
context.startActivity(intent);
}
});
Button economicsButton=(Button)rowView.findViewById(R.id.AllEconomicsButton);
economicsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent=new Intent(context,NewHeadlines.class);
intent.putExtra("economicbutton",currentwp.getEconomicsTitles());//to pass information to next activity
context.startActivity(intent);
}
});
Button sportsButton=(Button)rowView.findViewById(R.id.AllSportsButton);
sportsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent=new Intent(context,NewHeadlines.class);
intent.putExtra("sportsbutton",currentwp.getSportssTitles());//to pass information to next activity
context.startActivity(intent);
}
});
TextView firstNewsTitle=(TextView)rowView.findViewById(R.id.firstnewsTitle);
firstNewsTitle.setText(currentwp.getNewsTitles().get(0));
TextView firstEconomicsTitle=(TextView)rowView.findViewById(R.id.firsteconomicsTitle);
firstEconomicsTitle.setText(currentwp.getEconomicsTitles().get(0));
TextView firstSportsTitle=(TextView)rowView.findViewById(R.id.firstSportsTitle);
firstSportsTitle.setText(currentwp.getSportssTitles().get(0));
}
return rowView;
}
}
main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="326dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/AllnewsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/News" />
<TextView
android:id="#+id/firstnewsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/AllEconomicsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Economic" />
<TextView
android:id="#+id/firsteconomicsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/AllSportsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Sports" />
<TextView
android:id="#+id/firstSportsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout >
</LinearLayout >
each ListView row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="326dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/AllnewsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/News" />
<TextView
android:id="#+id/firstnewsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/AllEconomicsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Economic" />
<TextView
android:id="#+id/firsteconomicsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
< Button
android:id="#+id/AllSportsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Sports" />
< TextView
android:id="#+id/firstSportsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
You should pass your array inyo the constructor and then operate and handle that there. I am sure that you can send your array into your params, but you should make your Asynktask diferent fr string values, as currently you have. So the easy and best way is :
int indexofwp;
List<String> allResult = new ArrayList<String>()
public getParseData(int indexofwp, List<String> allResult)
{
super();
this.indexofwp = indexofwp;
This.allResult=allResult;
}
And thats all.
Regards.

Hide RelativeLayout when I touch inside a map

In my android app, I have a google maps v2 inside a fragment with marker of places. When I touch in a marker, it displays a RelativeLayout with the name of the marker. However, I would like that when I touch anywhere in the map, this RelativeLayout is hidden.
My code is this:
fragment_mapa.xml
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:gravity="center" />
<RelativeLayout
android:id="#+id/sliding_up"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#fff"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:clickable="true"
android:focusable="false"
android:animateLayoutChanges="true"
android:visibility="invisible" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="14sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>
</RelativeLayout>
Code where it creates the markers and onClick method to display the RelativeLayout
public void addItemsToMap() {
appState.mapa.clear();
if (appState.lista.isEmpty()) {
appState.readPlaces(5000, 0, appState.idCategoria);
}
appState.mapa.setOnMarkerClickListener(this);
appState.mapa.setOnInfoWindowClickListener(getInfoWindowClickListener());
LatLng miPosicion = new LatLng(obtLatitud, obtLongitud);
appState.mapa.addMarker(new MarkerOptions()
.position(miPosicion)
.title("Mi posiciĆ³n")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
for (int i = 0; i < appState.lista.size(); i++) {
LatLng posItem = new LatLng(appState.lista.get(i).latitud,appState.lista.get(i).longitud);
appState.mapa.addMarker(new MarkerOptions()
.position(posItem)
.title(appState.lista.get(i).nombre)
.snippet(appState.lista.get(i).descripcion)
/*.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))*/);
Log.v("MAPA", "Marker " + i + ": " + appState.lista.get(i).nombre);
}
}
#Override
public boolean onMarkerClick(final Marker marker) {
if(marker != null) {
//marker.showInfoWindow();
RelativeLayout slideLayout;
slideLayout = (RelativeLayout) findViewById(R.id.sliding_up);
slideLayout.setVisibility(View.VISIBLE);
Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
slideLayout.startAnimation(slide);
TextView t;
t = (TextView) findViewById(R.id.name);
t.setText(marker.getTitle());
return true;
} else {
RelativeLayout slideLayout;
slideLayout = (RelativeLayout) findViewById(R.id.sliding_up);
slideLayout.setVisibility(View.INVISIBLE);
return false;
}
}
// try this :
map.setOnMapClickListener(new OnMapClickListener() {
#Override
public void onMapClick(LatLng arg0) {
}
});

Categories

Resources