I tried using a second class that extends Activity but still crashing... This is what I have
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class Fragment1 extends Fragment{
private Button buttonOne ;
private Handler handler;
private Activity activity ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.fragement1_layout, container, false);
final Button button = (Button)V.findViewById(R.id.two);
ImageView imageView = (ImageView)V.findViewById(R.id.my_image);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button.setText("Hello");
}
});
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity, "Hello", Toast.LENGTH_SHORT).show();
}
});
return V;
}
}
I can't call a a toast message from the same class that extends fragment so I created one object that extends activity for a toast message but no luck :|. Can someone here help me.