Can I ask some help. we have smart android T.V box and already set up. we have 20 T.V channels set up. Now we want to create an android application that can select channel and display it to the screen just like the other cable provider that they have menu or list of their channels and you can select each of them to view on screen.The android app is installed in our smart android T.V box.
I have this simple running code but the problem is that I cannot show it again the list of my channels in order to select other channel I need to press the back button in order to show the list (discouraging I use listview). how can I achieve just like the same other cable provider that they can show the menu of channels on the left side and only will show if they press the menu.
this is what I have so far.
MyActivity.class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
String[] values = new String[] { "Nickelodeon", "Animal Planet", "CNN",
"MTV", "History Channel", "Discovery Channel", "National Geographic Wild", "MovieMAX HD",
"Science Channel", "TLC" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.videolist,R.id.label,values);
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String item = (String) getListAdapter().getItem(position);
Intent intent = new Intent(this, DisplayVid.class);
intent.putExtra("channelextra", item);
startActivity(intent);
}
Showvideo.class
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url = "url chanell here"; // static for my demo purpose only
video = (VideoView) findViewById(R.id.myVideo);
video.setVideoURI(Uri.parse(url));
mediacontroller = new MediaController(this);
mediacontroller.setMediaPlayer(video);
video.setMediaController(mediacontroller);
video.requestFocus();
video.start();
Bundle extras = getIntent().getExtras();
String item = extras.getString("channelextra");
}
Thank you in advance.
Related
I have made a Song List using ArrayList, and I got all the information and it can be passed to the second activity and open it on a new page.
What I want to have is when I click the song list, then it opens in a new page, and the new page shows the details and the image of the song.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView_Main=findViewById(R.id.listView_Main);
final Song song1 = new Song("Love Story","Taylor Swift","September 12,2008", "$1.29");
Song song2 = new Song("Lover","Taylor Swift","August 23,2019", "$1.29" );
Song song3 = new Song("I Forgot That You Existed", "Taylor Swift", "August 23,2019", "$1.29");
Song song4 = new Song("The Archer", "Taylor Swift", "August 23,2019", "$1.29");
Song song5 = new Song("I Think He Knows","Taylor Swift", "August 23,2019", "$1.29");
final List<Song> songs = new ArrayList<>();
songs.add(song1);
songs.add(song2);
songs.add(song3);
songs.add(song4);
songs.add(song5);
MainAdapter adapter = new MainAdapter(this, songs);
listView_Main.setAdapter(adapter);
listView_Main.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(view.getContext(),SongDetailActivity.class);
intent.putExtra("currentSong",(Serializable) songs.get(i));
startActivity(intent);
}
});
}
But my problem is in the second activity, I don't know how to get the detail of the song, and the images by using the setText.
So, I have made the song details in the String.xml file.
How can I get those details and the image in the second activity?
Also, I don't know how to get the position of the song list in the second activity, I mean the position of which song that I click, and It show the detail of that song I had clicked.
//Here is the second activity of the Song Details.//////
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_song_detail);
textViewSongDetail=findViewById(R.id.textView_SongDetail);
imageViewSongDetail=findViewById(R.id.image_SongDetail);
Song currentSong=(Song)getIntent().getSerializableExtra("currentSong");
}
First of all make sure you've implemented Serializable in your model class Song. Than your code will work fine.
And to receive the position you can send -
intent.putExtra("position", i); // to send
getIntent().getIntExtra("position", -1); //to receive (-1 is default value)
I have created Activity with a listView which uses setOnItemClickListener to determine which index has been pressed. Then it should pass the data into the next activity based on the selected index.
Passing of the values works, but it only works for the first listView index pressed after the app is reloaded.
To make it more clear. When the app is loaded I can press on any index of the ListView which will pass the data to the next Activity and display it correctly, but then when I go back to the ListView and select different index it still displays the same data from the previous index without updating it. Therefore, I have to reload the app to get new index results displayed.
Here is my ViewListActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_artist);
artistList = (ListView) findViewById(R.id.artistList);
databasehandler = new SqliteHandler(ViewArtistActivity.this);
allArtists = databasehandler.getAllArtists();
artistName = new ArrayList<>();
singleArtistDetails = new ArrayList<>();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (allArtists.size() > 0) {
for (int i=0; i < allArtists.size(); i++) {
ArtistModel artistModel = allArtists.get(i);
artistName.add(artistModel.getArtistName());
}
}
adapter = new ArrayAdapter(ViewArtistActivity.this, android.R.layout.simple_list_item_1, artistName);
artistList.setAdapter(adapter);
artistList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ArtistModel artistModel = allArtists.get(position);
singleArtistDetails.add(artistModel.getArtistName());
singleArtistDetails.add(artistModel.getArtistDOB());
singleArtistDetails.add(artistModel.getArtistBiography());
Intent intent = new Intent(ViewArtistActivity.this, SavedArtistDetailsActivity.class);
intent.putExtra("NAME", singleArtistDetails.get(0));
intent.putExtra("DOB", singleArtistDetails.get(1));
intent.putExtra("BIOGRAPHY", singleArtistDetails.get(2));
startActivity(intent);
}
});
}
Here is my code for displaying selected index results Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_artist_details);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
artistSavedNameLbl2 = (TextView) findViewById(R.id.artistSavedNameLbl2);
artistSavedDOBLbl2 = (TextView) findViewById(R.id.artistSavedDOBLbl2);
artistSavedBiographyLbl2 = (TextView) findViewById(R.id.artistSavedBiographyLbl2);
btnDeleteDetails = (Button) findViewById(R.id.btnDeleteDetails);
updateUI();
}
private void updateUI() {
artistSavedNameLbl2.setText(getIntent().getStringExtra("NAME"));
artistSavedDOBLbl2.setText(getIntent().getStringExtra("DOB"));
artistSavedBiographyLbl2.setText(getIntent().getStringExtra("BIOGRAPHY"));
}
Do one thing , initialize [not saying declare] your array list singleArtistDetails inside the onClick method, before adding any values to it.
like
singleArtistDetails = new ArrayList();
Hope this will help.
I am creating an android dictionary app with sounds... I have listview, when an item is selected, a new activity open, inside the new activity contains 4 textviews and an image button, the textviews function perfectly but the image button was not. The audio files are placed in raw folder. How can I put the specific sounds of an item that was clicked?
Here's the code:
MainActivityJava
public class MainActivity extends AppCompatActivity {
ListView lv;
SearchView sv;
String[] tagalog= new String[] {"alaala (png.)","araw (png.)","baliw (png.)","basura (png.)",
"kaibigan (png.)","kakatuwa (pu.)", "kasunduan (png.)","dambuhala (png.)",
"dulo (png.)","gawin (pd.)","guni-guni (png.)","hagdan (png.)","hintay (pd.)",
"idlip (png.)","maganda (pu.)","masarap (pu.)", "matalino (pu.)"};
int[] sounds= new int[]{R.raw.alaala,
R.raw.araw,
R.raw.baliw,
R.raw.basura,
R.raw.kaibigan,
R.raw.kakatuwa,
R.raw.kasunduan,
};
ArrayAdapter<String> adapter;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.listView1);
sv = (SearchView) findViewById(R.id.searchView1);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,tagalog);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String tagword =tagalog[position];
String[] definition = getResources().getStringArray(R.array.definition);
final String definitionlabel = definition[position];
String[] cuyuno = getResources().getStringArray(R.array.cuyuno);
final String cuyunodefinition = cuyuno[position];
String[] english = getResources().getStringArray(R.array.english);
final String englishdefinition = english[position];
Intent intent = new Intent(getApplicationContext(), DefinitionActivity.class);
intent.putExtra("tagword", tagword);
intent.putExtra("definitionlabel", definitionlabel);
intent.putExtra("cuyunodefinition",cuyunodefinition);
intent.putExtra("englishdefinition", englishdefinition);
startActivity(intent);
}
});
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String text) {
return false;
}
#Override
public boolean onQueryTextChange(String text) {
adapter.getFilter().filter(text);
return false;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
}
DefinitionActivity.java
public class DefinitionActivity extends AppCompatActivity {
MediaPlayer mp;
String tagalogword;
String worddefinition;
String cuyunoword;
String englishword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_definition);
TextView wordtv = (TextView) findViewById(R.id.wordtv);
TextView definitiontv = (TextView) findViewById(R.id.definitiontv);
TextView cuyunotv = (TextView) findViewById(R.id.cuyunotv);
TextView englishtv = (TextView) findViewById(R.id.englishtv);
ImageButton playbtn = (ImageButton) findViewById(R.id.playbtn);
final Bundle extras = getIntent().getExtras();
if (extras != null) {
tagalogword = extras.getString("tagword");
wordtv.setText(tagalogword);
worddefinition = extras.getString("definitionlabel");
definitiontv.setText(worddefinition);
cuyunoword = extras.getString("cuyunodefinition");
cuyunotv.setText(cuyunoword);
englishword = extras.getString("englishdefinition");
englishtv.setText(englishword);
}
playbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
you can pass the raw id in the intent extra and play it on meadiaPlayer
What you want to accomplish is pretty simple.
you can ofcourse pass the id.
But I created this method for your case you can paste it in your activity or class and make a call to it. In my case, I put this method in a class that holds all the common functions, methods, strings, etc. The choice is yours :
public static void playDisSound(Context c, int soundID){
//Play short tune
MediaPlayer mediaPlayer = MediaPlayer.create(c, soundID);
mediaPlayer.setOnCompletionListener( new OnCompletionListener(){
#Override
public void onCompletion( MediaPlayer mp){
mp.release();
}
});
mediaPlayer.start();
}
And this is how to use it in your case :
Example I want to play an audio track from :
int[] sounds= new int[]{R.raw.alaala,
R.raw.araw,
R.raw.baliw,
R.raw.basura,
R.raw.kaibigan,
R.raw.kakatuwa,
R.raw.kasunduan,
};
So I just do :
//TODO ~ pls. remember to define context inside "onCreate" as
//call this before "onCreate"
Context context;
//And do this inside "onCreate" :
context = getApplicationContext();
OR
context = MainActivity.this;
//Then here comes the solution, just make a call to the playDisSound method with the id , in this case the "sounds[postion_referencer_i]"
playDisSound(context, sounds[postion_referencer_i]);
//And now on the question of what your "position_referencer_i" would be .... it also depends on how you intend to pass the id.
Are your going to make a match between the position picked and the position of the sound. It depends on you. But I would have created a set of integers to signify which try I want to play and do a matching simple calculation between the position picked for the item clicked to arrive at the position_referencer_id.
//But simply : note that in your array if I want to play for example "R.raw.baliw" I would just call :
playDisSound(context, R.raw.baliw);
I hope this works perfectly for you. So if I elaborated too much. Do let me know if you may need to stream the sound so I would just paste/send you a very cool method I have been using here in an app am working.
//FINALLY PLS. Remember this : this method would play the sound alright but it wont hesitate to play the sound all over again if you repeat the process. So do remember to check if the sound did play and finished before allowing the user to repeat, if not it could lead to repeated or kind of two speakers playing from the same song but at different time. (And the user may start to think that there is problem with the app. Pls. be very logical and sensitive in using this method)
In solving that, you can disable the button or the UI element that initiates the sound playing until the sound has finished playing, by way of monitoring duration of the track (which I am sure you should know and inculcate into your logic or by simply listening if sound is already playing)
All the best. Era. :)
Ive searched for this all over the internet and there seems to be no simple explanation or tutorial on how to do this.
Basically, I want a layout that has a ListView where the user can click on an object and it will take them to the next layout.
In other words, using the listview as links to other layouts.
Everything Ive found on the internet has the end result of using a Toast... However I dont want a toast, i want to link to the next page.
Your question is slightly confusing so I'm going to make an assumption.
Is [LinearLayout1 LinearLayout2 Breadcrumb] suppose to be navigation or tabs that when selected insert their corresponding content into the Main Content?
If so I would suggest using fragments for each piece of content. Then when you click the navigation/tab, perform an animation of the fragment which slides the content in and out.
See the google docs for how to use fragments: http://developer.android.com/guide/components/fragments.html
See another stackoverflow answer for how to do the slide animation: Android Fragments and animation
or
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
Here is some code that outlines how to invoke an activity following a click on a list row. Hopefully you can adapt the Toast example you mention to make this work for you.
The basic idea is that you launch a new Activity with a new Intent. You can pass any data you need from the listView row as an extra in the Intent.
final static String[] months = new String[] {"Jan","Feb","Mar"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row_layout, R.id.text1, months);
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
int intItem = (int)id;
Intent intent= new Intent(this, SecondaryActivity.class);
intent.putExtra("MONTH", intItem);
startActivity(intent);
}
Why using ListView for it?
Each row must lead to different layout?
Its main benefits is in displaying dynamically changing data, but in your case data is constant, right?
Use vertical LinearLayout, fill it programmatically with "list elements", and add
leListComponent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(YourActivity.this, TargetActivity.class));
}
});
to each.
If i didn't get it, and you feel good of using some adapter, it can be like this:
public class LeWrapper {
private String caption;
private Class<? extends Activity> target;
...POJO here...
}
v.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//get leWrapper object from adapter
startActivity(new Intent(MenuActivity.this, leWrapper.getTarget()));
}
});
but its kinda overkill
Thanks for all the help guys. Sorry ive took my time replying. My solution is below :)
public class FP_WL1_ListView extends Activity {
private ListView lv1;
private String lv_arr[]={"Exercise Bike", "Treadmill", "Cross Trainer", "Squats", "Lunges"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.fitnessprograms_wlday_one);
lv1=(ListView)findViewById(R.id.list);
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
final TextView mTextView = (TextView)view;
switch (position) {
case 0:
Intent newActivity0 = new Intent(FP_WL1_ListView.this,FitnessPrograms_Wlone_sp.class);
startActivity(newActivity0);
break;
case 1:
Intent newActivity1 = new Intent(FP_WL1_ListView.this,FitnessPrograms_Wlone_Treadmill.class);
startActivity(newActivity1);
break;
case 2:
Intent newActivity2 = new Intent(FP_WL1_ListView.this,FitnessPrograms_Wlone_Crosstrainer.class);
startActivity(newActivity2);
break;
case 3:
Intent newActivity3 = new Intent(FP_WL1_ListView.this,FitnessPrograms_Wlone_Squats.class);
startActivity(newActivity3);
break;
case 4:
Intent newActivity4 = new Intent(FP_WL1_ListView.this,FitnessPrograms_Wlone_Lunges.class);
startActivity(newActivity4);
break;
}
}
});
} }
I'm quite new to this, I have checked for an answer at the forums here but I didn't find any answer that can really help me out. I'm trying to play a video from the res/raw folder. I have set up this code so far:
MediaPlayer mp;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview);
ListView l1 = (ListView) findViewById(R.id.listview);
l1.setAdapter(new EfficientAdapter(this));
l1.setOnItemClickListener(new OnItemClickListener() {
//Starts up a new activity, based on what listitem you press.
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent intent = new Intent(VideoButtonActivity.this, com.example.norskattrack.VideoActivity.class);
if(position==0){
System.out.println("Item 0");
intent.putExtra("video", 1);
startActivity(intent);
}
if(position==1){
System.out.println("Item 1");
intent.putExtra("video", 2);
startActivity(intent);
}
}
});
}
Uri video = Uri.parse("android.resource://com.package.app/raw/videoname");
That should let you play the video from the raw folder !
have a look at :
How to play videos in android from assets folder or raw folder?
Play Video From Raw Folder
Trying to play video from raw folder (VideoView)
All have excellent answers !