I am working on an android app. I finished my expandable list view and have every thing working. I want to add some more feature on the expandable list view.
What I want to do is. When the expandable list view is expanded, I want to click on the child and than lead me to a webpage.
Is there a method to do this?
Thanks for the help
String url = "http://www.website.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
Related
I am trying to create a like and dislike button. I use Checkboxes to do so.
In the XML code I have two checkboxes one called like and the other dislike
I'm trying to toggle between the like and dislike buttons. Such that they both cannot be switched on at the same time.
public void onLike(View view) {
if (dislike.isChecked()) {
dislike.setChecked(false);
}
Toast.makeText(this,"liked",Toast.LENGTH_SHORT).show();
}
The issue that I am having is that set setChecked(true) is not doing anything.
For more context, the XML for the checkbox is defined inside a fragment that has a cardview. Each item in the card view has the checkboxes.
the way I initialized the checkbox in the main activity is as follows: -
View cardViewLayout = getLayoutInflater().inflate(R.layout.text_row_item,null);
like = (CheckBox) cardViewLayout.findViewById(R.id.like);
dislike = (CheckBox) cardViewLayout.findViewById(R.id.dislike);
any ideas what's going on?
ok, I've figured out the solution. Since I am using a recycler view with a custom adapter I need to bind the onClick listener via an interface.
Here is a link to another post that will show the necessary steps to implement click listeners in adapters: https://stackoverflow.com/a/49969478/11379938
I am developing an android news app which has goal to show titles in one activity in listView, and by clicking on each title it must open another activity and show description, photo and also title. These are pulled from web in JSON.
For now, I have list view in first activity which has been populated with titles from JSON,using AsyncTask and SimpleAdapter, and now, I need some theory boost how to make further progress.
So, how can I select one title and by this title get other parts of JSON and show them in another activity?
Any advice?
Have an onClickListener on the items in listView. In the onClickListener get the title and start a new activity. For the new activity add the data you need to send.
Intent intent = new Intent(this, DetailActivity.class);
// add the data here
intent.putExtra("title", title);
startActivity(intent);
In DetailActivity.java
String title = getIntent().getExtras().getString("title");
make an API call with the above title
By this I mean, I have page A, and it has the users saved username as the title (so every user has a different title when logged in in their account). When I click the BUTTON it runs this onclick method, Intent q = new Intent(Profile.this, Profile.class); which I had thought it would basically just refresh the page, but instead the username is no longer there. I've tried multiple approaches but I am a beginner so I am having a lot of difficulty on what direction I go.
If you want to refresh page, you have to call recreate() method in butoon onclick method. Then the page will be recreated. So all fields in the page will be cleared. If you want to set the previous data in fields , then you can store them in shared preference. And set it again in all fields after refreshing.
To referesh the Current Activity, use this on Button Click.
public void onClick (View v)
{
Intent intent = getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
startActivity(intent);
}
I use the following codes to set background of view such as TextView, LinearLayout, and it works perfectly.
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setInt(R.id.textview, "setBackgroundColor", Color.parseColor(widgetTextColor.toString()));
But I try to set the background of CardView, it didn't works. I have tried
views.setInt(R.id.cardview, "setCardBackgroundColor", Color.parseColor(widgetTextColor.toString()));
Any workarounds?
Based on the developer documentation in this link, u cannot use cardview for App widgets
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
and a discussion about this already been over here What views can i use in an appWidget?
I'm trying to build an android app to stream online radio.
Currently it starts to shape up and works like this: When I click on a gridview item in MainActivity, it starts the AndroidMediaPlayer activity that streams a fixed url and shows a fixed image that doesn't represent the users selection.
Code: https://github.com/sthlmj/IORadio/tree/clickable-funktionen/app/src/main/java/se/mookito/ioradio
Now I am trying to make it work properly, so that if I click on a certain gridview item, the image and the stream url should play according to the selection. I started by trying to get the picture to be displayed correctly by trying to pass clicked position from the MainActivity
of the items ArrayList in MyAdapter via intent so that I can setImageResource on the second activity AndroidMediaPlayer according to selected image from the first activity MainActivity.
In the second activity I tried to get the intent data:
//Selected image id
int position = i.getExtras().getInt("id");
MyAdapter myAdapter = new MyAdapter(this);
//Set image id
ImageView imageView = (ImageView) findViewById(R.id.mp3Image);
imageView.setImageResource(myAdapter.items.get(position));
But I got: 'setImageResource(int)' in 'android.widget.ImageView' cannot be applied to '(se.mookito.ioradio.MyAdapter.Item)'
Call imageView.setImageResource(myAdapter.items.get(position).drawableId); instead.