Call layout from another class - java

Here I've called layout from another class and snippet as follows
class example extends Activity{
class2 btn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn.color();
}
}
//Another class(class2)
public class class2 extends Activity{
protected void color(){
View inflatedView = getLayoutInflater().inflate(R.layout.main, null);
LinearLayout layoutcolor=(LinearLayout) inflatedView.findViewById(R.id.linearcolor);
//some code
}
}
How can I call layout id in class2 by that I can display it from class example above code floods error.

class example extends Activity {
class2 btn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = new Class2();
btn.color(this);
}
}
// Another class(class2)
public class class2 {
protected void color(Activity mActivity) {
LinearLayout layoutcolor = (LinearLayout) mActivity.findViewById(R.id.linearcolor);
// some code
}
}
UPDATE: I created a sample and it works for me, just check your implementation. OR post full code.
package com.example.test;
import android.app.Activity;
import android.app.ListActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class sampleMediaPlayer extends ListActivity {
// Toast mToast;
private TextView selection;
class2 btn;
private static final String[] items = { "Computer Hardware", "Featured", "Information Technology",
"Software", "Technical"
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
items);
setListAdapter(adapter);
btn = new class2();
btn.color(this);
}
public void onListItemClick(ListView parent, View v, int position, long id) {
selection.setText(items[position]);
}
// Another class(class2)
public class class2 {
protected void color(Activity mActivity) {
ListView layoutcolor = (ListView) mActivity.findViewById(android.R.id.list);
layoutcolor.setBackgroundColor(Color.GREEN);
Log.i("NIMISH", "HEy ");
}
}
}

Related

Spinner OnItemSelected event not being called

I'm using the value in a spinner to help filter a list that will be the datasource for a RecyclerView. The OnItemSelect method never seems to be called when I use the spinner
It is an Android application, built in Java, using Pie for the OS. The project was created using the Basic Activity Template.
The Activity Class
package com.logicscrew.android;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.logicscrew.android.helpers.APIHelper;
import com.logicscrew.android.helpers.EmployeeAdapter;
import com.logicscrew.android.models.Department;
import com.logicscrew.android.models.Employee;
import java.util.ArrayList;
import java.util.List;
public class ViewByDepartment extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
private List<Employee> employees;
private List<Employee> filteredList;
private List<Department> deparments;
private RecyclerView rcView;
private EmployeeAdapter adapter;
private Context context;
private Spinner spinner;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
employees = new ArrayList<>();
deparments = new ArrayList<>();
filteredList = new ArrayList<>();
setContentView(R.layout.activity_view_by_department);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
spinner =(Spinner)findViewById(R.id.spnDepartments);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
context = this;
FetchTask task = new FetchTask(new AsyncResponse() {
#Override
public void processFinished(List<Employee> output) {
Log.i("Employees", "Finished");
}
});
DeptTask deptTask = new DeptTask(new DeptResponse() {
#Override
public void processFinished(List<Department> output) {
Log.i("Department", "Finished");
}
});
task.execute();
deptTask.execute();
rcView = findViewById(R.id.rcEmp);
adapter = new EmployeeAdapter(context, filteredList);
rcView.setLayoutManager(new LinearLayoutManager(context));
rcView.setAdapter(adapter);
ArrayAdapter<Department> deptAdapter = new ArrayAdapter<>(
this,
R.layout.spinner,
deparments
);
deptAdapter.setDropDownViewResource(
R.layout.spinner
);
spinner.setAdapter(deptAdapter);
spinner.setOnItemSelectedListener(this);
}
private void filter(){
filteredList.clear();
filteredList.addAll(employees);
for(Employee e : filteredList){
if(e.department != spinner.getSelectedItem()){
filteredList.remove(e);
}
}
adapter.swapDataSet(filteredList);
}
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
filter();
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
private class FetchTask extends AsyncTask<Void, Void, List<Employee>> {
public AsyncResponse delegate = null;
public FetchTask(AsyncResponse asyncResponse){
delegate = asyncResponse;
}
#Override
protected List<Employee> doInBackground(Void... voids) {
return new APIHelper().fetchItems();
}
#Override
protected void onPostExecute(List<Employee> items) {
employees.addAll(items);
filteredList.addAll(items);
adapter.notifyDataSetChanged();
delegate.processFinished(items);
}
}
private class DeptTask extends AsyncTask<Void, Void, List<Department>>{
public DeptResponse delegate;
public DeptTask(DeptResponse response){
delegate = response;
}
#Override
protected List<Department> doInBackground(Void... voids) {
return new APIHelper().fetchDepartments();
}
#Override
protected void onPostExecute(List<Department> items){
deparments.addAll(items);
delegate.processFinished(items);
}
}
public interface AsyncResponse{
void processFinished(List<Employee> output);
}
public interface DeptResponse{
void processFinished(List<Department> output);
}
}
What should happen is when the event is called, it filters the list, removing anyone in the list who is not in a specific department, but the event is never called.
You try put in onCreate :
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int myPosition, long myID) {
//your method
}
#Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
Problem was an Async Race Condition. Fixed by moving the Spinner setup into the processFinished method in DeptTask.
DeptTask deptTask = new DeptTask(new DeptResponse() {
#Override
public void processFinished(List<Department> output) {
Log.i("Department", "Finished");
ArrayAdapter<Department> deptAdapter = new ArrayAdapter<Department>(
getApplicationContext(),
R.layout.spinner,
deparments
);
deptAdapter.setDropDownViewResource(
R.layout.spinner
);
spinner.setAdapter(deptAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Log.i("Selected Item", "I AM INDEED WORKING");
filter((Department)spinner.getSelectedItem());
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
});

How to solve the '.MainActivity.<init>(MainActivity.java:16)' error?

EditText object is not created, why?
EditText editText=(EditText)findViewById(R.id.edittext);
This is for an App that extends AsyncTask class. fetchingData is a class that extens AsyncTask class.But it gives error on creating object of EditText.
package com.example.zafar.omdb_7;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
String string;
Button button;
public static TextView data;
//
private EditText editText = findViewById ( R.id.edittext );
//
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data=findViewById(R.id.fetched_data);
button=findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
//
#Override
public void onClick(View v) {
// string = editText.getText ().toString ();
fetchingData process= new fetchingData();
process.execute();
}
});
}
}
Your code should be something like this:
package com.example.zafar.omdb_7;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
String string;
Button button;
public static TextView data;
//
private EditText editText;
//
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data=findViewById(R.id.fetched_data);
editText = findViewById ( R.id.edittext );
button=findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
//
#Override
public void onClick(View v) {
// string = editText.getText ().toString ();
fetchingData process= new fetchingData();
process.execute();
}
});
}
}
You won't find the view before you set it on the activity. I hope this helps.
You can't use the following:
public class MainActivity extends AppCompatActivity {
// This won't work!
private EditText editText = findViewById ( R.id.edittext );
#Override
protected void onCreate(Bundle savedInstanceState) {
...
}
}
Because you can't call the findViewById before you set the Activity layout with setContentView(). It means that you can't find a view if you didn't have the layout yet.
So, edit your code to something like this:
public class MainActivity extends AppCompatActivity {
...
private EditText mEdtText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Now you have the layout, you can find the view
mEdtText = findViewById(R.id.edittext);
...
}
}

Can't resolve setOnItemSelectedListener

My goal is to make items from spinner list to change background color of main_activity.
But I can't get working setOnItemSelectedListener for some reason.
Spinner works fine, toast also, but setOnItemSelectedListener is getting error: "cant resolve the symbol..."
Couldn't find any help online that was applicable to my case.
Please see code below:
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Spinner;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Button;
import android.widget.ToggleButton;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import java.util.*;
public class MainActivity extends AppCompatActivity implements
AdapterView.OnItemSelectedListener {
private TextView tekst1;
private int ile = 1;
private Button klawisz1;
private ToggleButton onOff;
private Spinner spinner1;
public void setActivityBackgroundColor(int color) {
View view = this.getWindow().getDecorView();
view.setBackgroundColor(color);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tekst1 = (TextView) findViewById(R.id.tekst);
klawisz1 = (Button) findViewById(R.id.button);
onOff = (ToggleButton) findViewById(R.id.toggleButton);
spinner1 = (Spinner) findViewById(R.id.spinner);
spinner1.setOnItemSelectedListener((AdapterView.OnItemSelectedListener) this);
spinner1.setOnItemSelectedListener(this);
List<String> colors = new ArrayList<String>();
colors.add("White");
colors.add("Yellow");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
onOff.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if ((++ile%2)==0) {
spinner1.setVisibility(View.VISIBLE);
}
else{
spinner1.setVisibility(View.GONE);
}
}
});
}
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// On selecting a spinner item
//setActivityBackgroundColor(Color.YELLOW);
String item = parent.getItemAtPosition(position).toString();
if(selectedItem.equals("White"))
{
setActivityBackgroundColor(Color.WHITE);
}
else if(selectedItem.equals("Yellow"))
{
setActivityBackgroundColor(Color.YELLOW);
}
// Showing selected spinner item
//Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
public void buttonOnClick(View view) {
if ((++ile%2)==0){
tekst1.setText(new Date().toString());
klawisz1.setBackgroundColor(Color.RED);
}
else
{
tekst1.setText("Next click - TIME");
klawisz1.setBackgroundColor(Color.GREEN);
}
}
You have an extra } before the setOnItemSelectedListener() call and the code is outside of the onCreate() method. Code like spinner1.setOnItemSelectedListener(...) needs to be inside a method.
Try below code for your Spinner:
mTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// Do your stuff at item selection time.
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// Intentionally kept blank
}
});
It's becoz you have set setOnItemSelectedListener two times for spinner 1
\\ spinner1.setOnItemSelectedListener((AdapterView.OnItemSelectedListener)
this); \\not required
spinner1.setOnItemSelectedListener(this);
you should set only 1 setOnItemSelectedListener for spinner1
This code worked fine for me.Try it...
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity implements
AdapterView.OnItemSelectedListener {
List<String> colors;
private TextView tekst1;
private int ile = 1;
private Button klawisz1;
private ToggleButton onOff;
private Spinner spinner1;
public void setActivityBackgroundColor(int color) {
View view = this.getWindow().getDecorView();
view.setBackgroundColor(color);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tekst1 = (TextView) findViewById(R.id.tekst);
klawisz1 = (Button) findViewById(R.id.button);
onOff = (ToggleButton) findViewById(R.id.toggleButton);
spinner1 = (Spinner) findViewById(R.id.spinner);
klawisz1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buttonOnClick(view);
}
});
spinner1.setOnItemSelectedListener(this);
colors = new ArrayList<String>();
colors.add("White");
colors.add("Yellow");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
onOff.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if ((++ile % 2) == 0) {
spinner1.setVisibility(View.VISIBLE);
} else {
spinner1.setVisibility(View.GONE);
}
}
});
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// On selecting a spinner item
//setActivityBackgroundColor(Color.YELLOW);
String item = colors.get(position);
if (item.equals("White")) {
setActivityBackgroundColor(Color.WHITE);
} else if (item.equals("Yellow")) {
setActivityBackgroundColor(Color.YELLOW);
}
// Showing selected spinner item
//Toast.makeText(parent.getContext(), "Selected: " + item,
//Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public void buttonOnClick(View view) {
if ((++ile % 2) == 0) {
tekst1.setText(new Date().toString());
klawisz1.setBackgroundColor(Color.RED);
} else {
tekst1.setText("Next click - TIME");
klawisz1.setBackgroundColor(Color.GREEN);
}
}
}

TextView does not show log

Okay I am new with android and i have been following a course but there are somethings that i don't understand.
This is LifeCycleT activity.
package com.example.killtheviolence.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class LifeCycleT extends Activity {
StringBuilder builde = new StringBuilder();
TextView textview;
private void log(String text) {
Log.d("LifeCycleT", text);
builde.append( builde.toString() );
builde.append("\n");
textview.setText(builde.toString());
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText(builde.toString());
setContentView(textview);
}
protected void onResume() {
super.onResume();
log("resume");
}
protected void onPause() {
super.onPause();
log("paused");
if(isFinishing()) {
log("death");
}
}
}
Where this came from? From a ListView.
package com.example.killtheviolence.myapplication;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
String prueva[] = {"LifeCycleT","item2","item3","item4",
"item5 ", "item6 "};
public void onCreate(Bundle savedInstanceSate){
super.onCreate(savedInstanceSate);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, prueva));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String gate = prueva[position];
try {
Class<?> inst;
inst = Class.forName("com.example.killtheviolence.myapplication." + gate);
Intent intent = new Intent(this, inst);
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
That's the main activity.
What I want to do show in the TextView the Log.d in the screen but I get an error:
Unable to resume activity
{com.example.killtheviolence.myapplication/com.example.killtheviolence.myapplication.LifeCycleT}:
java.lang.NullPointerException
So I looked for a reason (meaning for a NullPointerException and it was that
I used TextView before initializing on the line textview.setText(builde.toString());
What I did was create an instance of TextView in log function.
private void log(String text) {
Log.d("LifeCycleT", text);
builde.append(builde.toString());
builde.append("\n");
TextView textview = new TextView(this);
textview.setText(builde.toString());
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText(builde.toString());
setContentView(textview);
}
Why have I to create two instances of TextView? And why have I to setText twice? Why doesn't it show anything in the TextView? (only shows when i wrote a "string" in the arguments of setText.)
fix your onCreate to set the field parameter not a local parameter:
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
textview = new TextView(this); // << This used to be a local var, thats why NPE
textview.setText(builde.toString());
setContentView(textview);
}
Then remove the 2nd creation of the TextView from log
private void log(String text) {
Log.d("LifeCycleT", text);
builde.append("\n");
builde.append(text);
textview.setText(builde.toString());
}
Also notice that I changed your StringBuilder to append the text that you pass as a parameter into your log method

Webview Fragment Error

Im trying to implement a webview inside one of my pages but I am using an "else if" for the fragment. Im getting and error on the line "changeFragment(new CalendarFragment());", saying that it cannot be applied to my Calender Fragment file. Any help solving this would be greatly appreciated.
MainActivity.java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.special.ResideMenu.ResideMenu;
import com.special.ResideMenu.ResideMenuItem;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class MenuActivity extends FragmentActivity implements View.OnClickListener{
private ResideMenu resideMenu;
private MenuActivity mContext;
private ResideMenuItem itemHome;
private ResideMenuItem itemProfile;
private ResideMenuItem itemCalendar;
private ResideMenuItem itemSettings;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = this;
setUpMenu();
changeFragment(new HomeFragment());
Parse.initialize(this, "123", "IHecHh");
PushService.setDefaultPushCallback(this, MenuActivity.class);
}
private void setUpMenu() {
// attach to current activity;
resideMenu = new ResideMenu(this);
resideMenu.setBackground(R.drawable.menu_background);
resideMenu.attachToActivity(this);
resideMenu.setMenuListener(menuListener);
//valid scale factor is between 0.0f and 1.0f. leftmenu'width is 150dip.
resideMenu.setScaleValue(0.6f);
// create menu items;
itemHome = new ResideMenuItem(this, R.drawable.icon_home, "Home");
itemProfile = new ResideMenuItem(this, R.drawable.icon_profile, "Profile");
itemCalendar = new ResideMenuItem(this, R.drawable.icon_calendar, "Calendar");
itemSettings = new ResideMenuItem(this, R.drawable.icon_settings, "Settings");
itemHome.setOnClickListener(this);
itemProfile.setOnClickListener(this);
itemCalendar.setOnClickListener(this);
itemSettings.setOnClickListener(this);
resideMenu.addMenuItem(itemHome, ResideMenu.DIRECTION_LEFT);
resideMenu.addMenuItem(itemProfile, ResideMenu.DIRECTION_LEFT);
resideMenu.addMenuItem(itemCalendar, ResideMenu.DIRECTION_RIGHT);
resideMenu.addMenuItem(itemSettings, ResideMenu.DIRECTION_RIGHT);
// You can disable a direction by setting ->
// resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT);
findViewById(R.id.title_bar_left_menu).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
resideMenu.openMenu(ResideMenu.DIRECTION_LEFT);
}
});
findViewById(R.id.title_bar_right_menu).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
resideMenu.openMenu(ResideMenu.DIRECTION_RIGHT);
}
});
}
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return resideMenu.dispatchTouchEvent(ev);
}
#Override
public void onClick(View view) {
if (view == itemHome){
changeFragment(new HomeFragment());
}else if (view == itemProfile){
changeFragment(new ProfileFragment());
}else if (view == itemCalendar){
changeFragment(new CalendarFragment());
}else if (view == itemSettings){
changeFragment(new SettingsFragment());
}
resideMenu.closeMenu();
}
private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() {
#Override
public void openMenu() {
Toast.makeText(mContext, "Menu is opened!", Toast.LENGTH_SHORT).show();
}
#Override
public void closeMenu() {
Toast.makeText(mContext, "Menu is closed!", Toast.LENGTH_SHORT).show();
}
};
private void changeFragment(Fragment targetFragment){
resideMenu.clearIgnoredViewList();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.main_fragment, targetFragment, "fragment")
.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
// What good method is to access resideMenu?
public ResideMenu getResideMenu(){
return resideMenu;
}
}
CalendarFragment.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class CalendarFragment extends Activity implements OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar);
WebView wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://www.xxxx.com");
wv.setWebViewClient(new WebViewClient());
}
#Override
public void onClick(View v) {
}
private class Callback extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return (true);
}
}
#Override
public void onPause() {
super.onPause();
}
#Override
public void onResume() {
super.onResume();
}
}
your CalendarFragment is not actually a Fragment but an Activity since you extended Activity
public class CalendarFragment extends Activity
but the changeFragment method takes a parameter a Fragment, causing a compile time error,

Categories

Resources