Issue
https://stackoverflow.com/a/14164318/3575963
Here, he used
View myFragmentView = inflater.inflate(R.layout.fragment_a, container, false);
From parent class. Also I don't have inflater
in my parent, it is a map.
And from asynctask doitbackground
, I returned 5 arraylists to make textview
in postexecute
.
But I can't do because I can't use findviewbyid because I can't get activity. I got context but it does not do anything.
Here is my postexecute
protected void onPostExecute(Wrapper wrap){
TextView name = new TextView (mContext);
TextView type = new TextView (mContext);
TextView location = new TextView (mContext);
TextView distance = new TextView (mContext);
List<Double> dist = new ArrayList();
List<String> loc = new ArrayList();
List<String> nme = new ArrayList();
List<String> typ = new ArrayList();
List<Calendar> start = new ArrayList();
List<Calendar> endd = new ArrayList();
dist = wrap.getDist();
loc = wrap.getLocation();
nme = wrap.getName();
typ = wrap.getType();
start = wrap.getsDate();
endd = wrap.geteDate();
int idx = -1;
LinearLayout shw_evnt = (LinearLayout) shw_evnt.findViewById(R.id.);
for(Double dis:dist){
idx++;
name.setText(nme.get(idx));
type.setText(typ.get(idx));
location.setText(loc.get(idx));
distance.setText(dist.get(idx).toString()+" meters");
This part is faulty
LinearLayout shw_evnt = (LinearLayout) shw_evnt.findViewById(R.id.);
I tried other things but it did not work. I will use another layout that was not used before.
show_events.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
android:id="@+id/shwevnt"
</LinearLayout>
Here caller mapactivity class
public class MapActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private int strokeColor = 0xffff0000; //red outline
private int shadeColor = 0x44ff0000; //opaque red fill
private int count=0;
private GoogleMap googleMap;
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
private LocationRequest mLocationRequest;
private Context mContext;
private String TAG = "Chic";
private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
private int radius;//in meters
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "inside map oncreaste");
mContext = getApplicationContext();
View myFragmentView = inflater.inflate(R.layout.show_events, container, false);
super.onCreate(savedInstanceState);
setUpMapIfNeeded();
Log.d(TAG, "buildgoogleapi called");
buildGoogleApiClient();
Log.d(TAG, "after buildgoogleapi called");
}//end of oncreate
here error on that
View myFragmentView = inflater.inflate(R.layout.show_events, container, false);
because i dont have inflater
I dont want to return from postexecute to main class or another wrapper class. I think i can do inside postexecute, cant i?
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
if i do this, i will take current view, not the view i want to create?
I tried
private Inflater inflater;
View myFragmentView = inflater.inflate(R.layout.show_events, container, false);
Solution
Just pass the Activity as a parameter to the AsyncTask class. See here. Note that its bad practice to store context as a member variable since the context may change.
Answered By - Daniel Kobe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.