whati need to do?
activity
error
toolbar
toolberinactivityxml
It seems you have imported the wrong toolbar in the activity.
You used androidX.toolbar in xml and imported android.toolbar. Try to import the relevant toolbar in the activity or press ctrl+shift+O to optimize imports.
Related
I'm trying to update the subtitle of my toolbar from an adapter class. I've tried the accepted answer from here.
((OrderActivity) context.getSupportActionBar().setSubtitle("Bla Bla"));
Order Activity is the calling activity and this line of code is in the adapter. The context being used here is passed from the calling/parent activity.
I'm getting a 'cannot resolve method getSupportActionBar()'.
try ((OrderActivity) context).getSupportActionBar().setSubtitle("Bla Bla");
I have an activity called PeopleActivity, with a layout xml of activity_people.xml.
This activity is using the Android Studio Navigation Drawer Activity template.
I have a list view in the content_people.xml file named people_list. When I attempt to associate this control in the back end, it is unable to find the id. I am attempting it as:
peopleList = (ListView) findViewById(R.id.people_list);
Any insight would be greatly appreciated.
EDIT: Did an update to the code section to reflect the correct control referenced.
you should declare your listview like this:
peopleSearch = (ListView) findViewById(R.id.people_list);
not as EditText
I found the answer. You cannot use capital letters in the naming of your controls. Once I fixed this, everything worked fine.
I'm not sure if this is bad practice or not, or what errors I could encounter in the future if I do this.
Basically I'm trying to switch two fragments with a FragmentManager, and I need to do this when I press a button that is inside my first fragment. I declare the fragment in the main.xml file like this:
<fragment
class="com.example.MyApp.ButtonFragmentOne"
android:id="#+id/button_fragment_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout="#layout/button_fragment_one"
/>
I can access my button from my first fragment just fine in my Main.java file, but I'm not sure if I should do this or not.. Someone told me that it's a bad idea, but they couldn't really explain why. Should I be doing the onClick listener from my Main.java file, or inside the ButtonFragmentOne.java file? Does it matter at all?
Any documentation or help would be appreciated! Thanks!
Your problem is easy to solve. There is a documentation from Google.
To communicate between fragments you have to call your activity via an interface and the activity has to manage the switch between the fragments.
You can call below code on click of button of first fragment,
SecondFragment secFrag = new SecondFragment();
FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
fragTransaction.replace(R.id.fragment_container,secFrag );
fragTransaction.addToBackStack(null);
fragTransaction.commit();
Official Documents :
http://developer.android.com/training/basics/fragments/fragment-ui.html
http://developer.android.com/training/basics/fragments/communicating.html
I'm trying to make a MenuTab with android but I have a lot of problems. Here's my code
tabHost = (TabHost) A.findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1 = tabHost.newTabSpec("tab_news");
spec1.setIndicator(
"", //Load news titlte
A.getResources().getDrawable(R.drawable.icon_menu_news) //Load icon
);
spec1.setContent(R.id.tab_news);
tabHost.addTab(spec1);
First question, why if I put "title" inside indicator I don't see the image?
Well now I want to create a new activity when this tab is selected.
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
firstTabSpec.setIndicator("First Tab Name").setContent(new Intent(A,Test.class));
This example doesn't work... I get this error
09-15 23:19:26.861: E/AndroidRuntime(14938): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.workactivity/com.workactivity.MainActivity}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
I try to google about setup but I get no matchs...
I follow this tutorial: http://www.androidpeople.com/android-tabhost-tutorial-part-1
And this one: http://android-pro.blogspot.com.es/2010/08/tabbed-applications-in-android.html
Thanks for all :)
Look at this, sounds like just the same problem solution.
While not seeing your code maybe you need change Activity base class from Activity to ActivityGroup
The below code was automatically generated when I started a new android project.
I'm getting an error on the "R.layout.main" saying it does not exist.
I do in fact have a main.xml and I can see the layout change as I edit it in the Graphical Layout tab.
How can I fix this so I can run my application?
public class ComplimentGeneratorActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
The package name of the R file and the package name of your source code may not match. Make sure the package your code is in is the same as the package defined in the manifest file. Otherwise you will need to import the R file with the full package name (ex: com.example.R.layout.main).
If they match, for some reason your R file was not generated properly. Try cleaning your project.
Also, start accepting some answers. I almost didn't answer this because of your horrible acceptance rate.
This may be a very simple answer, but it has happened to me before. Try to restart eclipse. File -> Restart
Try to import the R.java file with the full path inside the main activity class file...
import com.example.packagename.R;
Hope, this will solve your query.