Sorry I recreate my post and PLZ this time just answer if you know or have an idea about the answer, i'm tired about people answering "Why you do that ?" Or "Omg you don't know Android ?".
In my MainActivity (extends Activity), i want to call my class ListDataView (extends View) which displays a ListView.
Is it possible ? Don't ask me why i want to do that, just answer Yes or No and Why plz.
TY
ps : sry for my behavior, but really tired about some useless guys in this community.
What you really want?
In your mainView show the ListDataView: You should check the fragments I think that it is that you really want to do. https://stackoverflow.com/questions/5710573/need-a-fragments-example
Add a button (for example) to go to the other view: create a new activity with the new view and do an intent. http://www.vogella.com/articles/AndroidIntent/article.html
Hope it will helps you.
so you have one Activity and one view class called ListDataView that displays a list of data. and you want to set ListDataView as the view of your activity. Please correct me if my understanding is not correct..
You can create a object of your class ListDataView and set that object as the view of the Activity by using setContentView() method as shown in the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
ListDataView view = new ListDataView(this);
//may be some initialization of the ListDataView
setContentView(view)
}
Related
I am stuck in a situation where I have to move from recycler view fragment to an activity but doesn't find a working solution for that.please help
Thanks
Basically, you just need a Context instance to open any Activity:
context.startActivity(new Intent(context, SomeActivity.class)
I assume you are asking about opening new Activity depending on which RecyclerView item was clicked. In that case, you should add View.OnClickListener to the ViewHolder.
The easiest way is to handle click inside ViewHolder. Context instance is accessible from any View using the View.getContext() method. However, I prefer to delegate click back to Fragment/Activity and then open a new screen from there. Check out the sample here: https://github.com/IvanShafran/abbyy-mobile-school-2019/tree/master/RecyclerViewSample
I need show a TextView in all Activities, but is much work to do it one by one, because I have +10 Activities.
My objective is when I click in a button, show a textview ("Importing ...") at the bottom of the application. This textview will disappear when I receive a push notification, and I owe a pop up with the response (the pop up also has to appear in any activity).
My project has a custom abstract BaseActivity and all activities extends it.
public abstract class BaseActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void setActionBar(#IdRes int idResToolbar) {
Toolbar toolbar = (Toolbar) findViewById(idResToolbar);
setSupportActionBar(toolbar);
updateFont(toolbar);
}
// ...
}
I think I could use for my purpose but not how to do it.
If anyone has any suggestions I will be happy to hear it.
Thanks in advance.
Use fragments for your content (instead of different activites) you then can add global views to the activity, which holds the fragments.
If you don't want to do that, you'd have to modify the layout(s) in your Base class.
I would suggest you to use a PopupWindow that contains the text view and create a separate class that initializes the PopupWindow on the basis of context given to it.
Now in all your Activities you will have the control of showing and hiding the window as you want. Make sure to make all utility methods required in the separate class to avoid coherence for example hiding and showing the window. setting text of text view of the window and etc.
You can write in onCreate() of your base activity something like
setContentView(R.layout.base_layout);
And in every other Activity at start of onCreate() method, just use super.onCreate()
And more than that to support different layouts add something like this in onCreate() (example for one of activities)
LayoutInflater inflater = getLayoutInflater();
inflater.inflate(R.layout.activity_1_layout,rootGroup)
where rootGroup is a ViewGroup in your Base Activity, in which you will add additional components for every other activity
Create a service, which creates a View which can be drawn over other apps (will require the relevant permission in the manifest)
You could use one of the open source libraries available like this or refer to this example
It's better you use fragments instead of using many activities. However, if you don't wanna do so, I suggest you create a factory which will generate a textview to all activities. Then you must add it into each activity's view.
i wish you all a good day.
First of all, sorry if i mispell frecuently because i din't know how to write on english, at least properly. But that's not a problem for all the response's that u can give me because i can read english pretty well (yeah, im a lazzy a.s.s. to learn it as should have to).
Second, im learning android right now and had been developing an app for like a month. The problem is that my app have an actionbar Menu on the Activity that contains 3 fragments THAT ARE ADDED BY a VIEWPAGER, so i can't cast them in activity to run their methods.... Thats a big problem!. Each one of those fragments have several EditText, and what i want is to USE MY ACTIVITY ACTIONBAR MENU ITEM CLICK to store all data from the EdtiText's and store it in an SQLite Database; one table per fragment.
I have been done everything and the only thing that i need isis to know how to call methods from the three fragments when pressing an item, on the onOptionClickListener OF THE MENU ITEM OF MY ACTIVITY. (The most important thing is that is the menu of my activity, not the fragment's, and i cant instantate the fragments on my activity because im using viewpager to create them).
Sorry again of my mispell's, and sorry for not posting my code, but, is really large so instead of make it clear my problem im gonna confuse everbody, so its better that you can help me withow the need of my really large code, so thanks for understanding and helping me.
There is a class for this.
Check Observer class. actually is nothing too complicated. You can easily remake this behave.
*just make a interface with a method
public interface MyObserverInterface {
//the code that will run when a save button is clicked in your menu
//fragment
public void starAction();
}
*make your fragments implament this interface.
*create a second class in wich you will get a reference to your fragments
public class MyObserver {
List<Fragment> listFragments;
//make sure your fragments implement the MyObserverInterface interface
public MyObserver(Fragment fragment1, Fragment fragment2) {
listFragments = new ArrayList<Fragment>();
listFragments.add(fragment1);
listFragments.add(fragment2);
}
public void startActionInAllFragments(){
for(int n=0;n<listFragments.size();n++){
listFragments.get(n).starAction();
}
}
}
Now just create an instance of MyObserver class in your fragment and call its method startActionInAllFragments()
let me know if it worked for u.
I currently have the following situation:
1) The "main view" which contains the EditText I'm trying to update. (Let's call it mainView)
2) A fragment that is opened whenever I click in a button that is contained in the "main view", the
fragment receives mainView as parameter.
3) An OnClickListener which is set to a button that is contained by the fragment. This listener receives the fragment as parameter.
Basically what I need to do is, each time I click on the button that triggers the listener, I need to update the editText, however it doesn't seem to be working. I believe it has something to do with "notifying" the view, but I haven't been able to get it working no matter what I try. After I update the text I close the fragment and
Basically the code is the following:
public void onClick(View v){
String newMessageContent = "hello world";
fragment1.mainView.editText1.setText(newMessageContent);
FragmentManager manager = this.fragment1.getActivity().getFragmentManager();
manager.beginTransaction().replace(R.id.container,this.fragment1.mainView.getPlaceHolderFragment()).commit();
}
Please note that I have simplified the problem a little bit and changed the name of the fragment/views in order for you guys to understand better. The text "hello world" is actually dynamic, and depends no another parameter that is received by the OnClickListener.
After I click the fragment does get replaced, so I know the onClickListener is working correctly, however I believe there's something wrong with the way the data change is being notified.
I've already looked at many SO questions, however none of them have helped me to achieve what I need.
Any help is appreciated, thanks.
I suggest implementing an interface, say, IUpdateFromFragment with method, say, onUpdate(String message), then let activity implement that interface and inside the fragment just call something like ((IUpdateFromFragment)this.getActivity()).onUpdate(newMessageContent);
I realized the problem was that each time I replaced the fargment via the fragmentManager, the method setActivityView was being called again, which replaced the EditText content.
In order to avoid this, I manually removed the fragment (instead of replacing it), doing the following:
FragmentManager manager = this.selectTemplateFragment.getActivity().getFragmentManager();
manager.beginTransaction().remove(this.selectTemplateFragment).commit();
Update the fragment via transaction, then within the fragment1 class OnViewCreated, you can do mainView.editText1.setText("whatever");
The way you're doing this now, I'm surprised isn't throwing an exception since the view isn't inflated yet.
i have TabHost app with Three Activities,in first tab i created a viewGroup.every thing working fine
my problem is i want to get TabActivity instance from the view group's chaild Activity
How can i get this... i am trying like this in View group's child activity
Tab_Activity TabObj = (Tab_Activity)getParent();
abObj.someMethod();
i got Class Cast Exception,i think i am getting View group Activity instance,
i want to get TabActivity instance,please help me if any one knows answer
Tab_Activity TabObj = (Tab_Activity)getParent().getParent();
treid like this also...
Thanx in Advance
I just tested it: if your TabActivity properly extends the standard android.app.TabActivity then Tab_Activity TabObj = (Tab_Activity)getParent(); should work as designed.
EDIT: AH. You want to do something like this:
Tab_Activity TabObj = (Tab_Activity)((ChildActivity)getContext()).getParent();
from inside the ViewGroup.