Android Studio Display Long in Button Text - java

How would I go about displaying a Long or Int inside of a button element's text field (or a TextView)? Would the same method work for displaying a String inside the text field? Thanks.
Here is my code for MainActivity
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.view.MenuInflater;
import android.view.View;
import android.view.Menu;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
import androidx.appcompat.widget.PopupMenu;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import java.io.File;
public class MainActivity extends AppCompatActivity {
Button mainstorage;
private AppBarConfiguration mAppBarConfiguration;
private static final int REQUEST_WRITE_STORAGE = 112;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
StatFs statFs = new
StatFs(Environment.getRootDirectory().getAbsolutePath());
long blockSize = statFs.getBlockSize();
long totalSize = statFs.getBlockCount()*blockSize;
long availableSize = statFs.getAvailableBlocks()*blockSize;
long freeSize = statFs.getFreeBlocks()*blockSize;
String internalSize = Long.toString(blockSize);
myBtn.setText(internalSize);
}
}
And my XML for the Fragment.
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">
<LinearLayout
android:background="#android:color/transparent"
android:id="#+id/firstrow"
android:layout_height="0dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="start"
app:layout_constraintHeight_percent="0.22"
tools:ignore="MissingConstraints">
<Button
android:contentDescription="#string/goInternalDesc"
android:id="#+id/main"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/transparent"
android:drawableTop="#drawable/storage"
android:minWidth="20dp"
android:text="Main Storage"
android:minHeight="20dp" />
</LinearLayout>
I am wondering why I am getting a build error when trying to set the text of the button to the String in my code. I thought it might be because I had set the text of the button in the XML but removing that had no effect- I am still getting a "Cannot resolve symbol" error on my MainActivity.

You can either use
btn.setText(String.valueOf(myLong));
btn.setText(String.valueOf(myInt));
Or
btn.setText(Long.toString(myLong));
btn.setText(Integer.toString(myInt));

I normally do this way
btn.setText(number+"");

For example:
If you have a button called jButton1, you just need to use this code:
String test = String.valueOf(your_int_or_long);
jButton1.setText(test);
And yes, for the text field is the same method.

Related

app crashes when getting a reference on android studio

I'm a newbie in programming and stuff.. I'm using the android-youtube-player package from Pierfrancesco Soffritti.. and when I try to Get a reference to YouTubePlayer and run the app it crashes..
`
package com.example.youtuuuuuuuuuuuuuuube;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.YouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.ui.DefaultPlayerUiController;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.ui.PlayerUiController;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.ui.menu.YouTubePlayerMenu;
public class MainActivity extends AppCompatActivity {
private YouTubePlayer youTubePlayer;
private YouTubePlayerView youTubePlayerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void playvideo(View v){
youTubePlayer.loadVideo("S0Q4gqBUs7c", 1f);
}
}
`
my XML code
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="#+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:videoId="S0Q4gqBUs7c"
app:autoPlay="true"
/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="playvideo"
android:text="Button" />
I tried to get the reference using OnStart() method, added a button but all of that don't work :(

Add more than one element to set content view

i have a app set up which loads a website into the app which works fine, when i try to add another element to the content view the app crashes without a error, How can i add more than one element to my set content view? ive tried it with frame layout and more but they all dont seem to work.
Here is my code
package com.example.fiercepcs;
import android.content.Context;
import android.os.Bundle;
import com.example.fiercepcs.databinding.ActivityMainBinding;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.app.Application;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout screenLayout = new LinearLayout(this);
screenLayout.setOrientation(LinearLayout.VERTICAL);
Button button = (Button) findViewById(R.id.button);
WebView myWebView = new WebView(getApplicationContext());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.fiercepc.co.uk");
setContentView(myWebView);
setContentView(button);
}
}
my activity main xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.FiercePcs.AppBarOverlay" />
<include
android:id="#+id/include"
layout="#layout/content_main" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:translationZ="-5dp">
</WebView>
<Button
android:id="#+id/button"
android:layout_width="312dp"
android:layout_height="179dp"
android:scaleX="1"
android:scaleY="1"
android:text="#string/button"
android:visibility="visible"
app:layout_anchor="#+id/include"
app:layout_anchorGravity="center" />
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
your app crashes because your are trying to set button view and webView as the root layout, don't do that, inflate or bind the root of your layout with ActivityMainBinding
do it like this :
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bindnig = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
LinearLayout screenLayout = new LinearLayout(this);
screenLayout.setOrientation(LinearLayout.VERTICAL);
Button button = (Button) findViewById(R.id.button);
WebView myWebView = new WebView(getApplicationContext());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.fiercepc.co.uk");
}
}

How to change multiple fragments by clicking on a single button in android?

Greeting!
I’m practicing on fragments topic. My main issue is how to change multiple fragments by clicking a single button “NEXT” or “PREVIOUS” as you may know some apps or books change pages by clicking on the next or previous buttons. If there are only two are four fragments then no issue to add buttons but what if there are multiple fragments like 50 or 100? First I try to find solutions from Google and YouTube but I find that we can change pictures through this method. Is it possible that we can change fragments through this method or not if possible so please some articles with the same solutions to share your experience? Or I should need to use images to do this. My main activity java code and XML code are below and the first fragment and code other three fragments are also the same.
// Main_Activity.java
package com.test.fragment_practice;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.test.fragment_practice.Fragments.FirstFragment;
import com.test.fragment_practice.Fragments.ForthFragment;
import com.test.fragment_practice.Fragments.SecondFragment;
import com.test.fragment_practice.Fragments.ThirdFragment;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
LinearLayout layout;
Button btn1,btn2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (LinearLayout) findViewById(R.id.linearLayout2);
btn1 = (Button) findViewById(R.id.btnpre);
btn2 = (Button) findViewById(R.id.btnnxt);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
FirstFragment fragment = new FirstFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.linearLayout2, fragment);
fragmentTransaction.commit();
}
});
btn2.setOnClickListener((view) ->{
SecondFragment fragment2 = new SecondFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.linearLayout2, fragment2);
fragmentTransaction.commit();
});
}
}
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF3700B3"
android:orientation="horizontal">
<Button
android:id="#+id/btnpre"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:backgroundTint="#FF0000"
android:text="Previous"
android:textColor="#6900FF"
android:textSize="24sp" />
<Button
android:id="#+id/btnnxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:backgroundTint="#FFFF00"
android:text="Next"
android:textColor="#6900FF"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</LinearLayout>
// First_Fragment.java
package com.test.fragment_practice.Fragments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.test.fragment_practice.R;
import com.test.fragment_practice.SecondActivity;
public class FirstFragment extends Fragment {
public FirstFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.fragment_first, container, false);
}
}

How to display database data from an activity?

I have an android application and i want to display database data in one of the activity in a listview. I already managed to display it in a listview on a fragment, but now i want to apply the same process to an activity.
I already tried to take the code i used to display data on my fragment, and use it for my activity, but didn't work even after making some change, and i'm still getting an error on #Override.
Here is my activity code :
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.example.schoolapp.DBHelper;
import com.example.schoolapp.R;
import java.util.ArrayList;
import java.util.HashMap;
public class AdminEvenementActivity3 extends AppCompatActivity {
private TextView Date;
DBHelper SchoolDB;
String CONTENU_ANG;
String CONTENU_ANG_DATE;
HashMap<String,String> user;
ListView CDCANGList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_evenement3);
Date = (TextView) findViewById(R.id.Date);
Intent incomingIntent = getIntent();
String date = incomingIntent.getStringExtra("date");
Date.setText(date);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_cdc_ang, container, false);
CDCANGList = rootView.findViewById(R.id.CDCANGList);
SchoolDB = new DBHelper(AdminEvenementActivity3.this);
SQLiteDatabase db = SchoolDB.getReadableDatabase();
ArrayList<HashMap<String, String>> userList = new ArrayList<>();
Cursor view = db.rawQuery("SELECT CONTENU_ANGLAIS_DATE, CONTENU_ANGLAIS FROM CONTENU_COURS_ANGLAIS", null);
if (view.moveToFirst()){
do {
// Passing values
user = new HashMap<>();
CONTENU_ANG = view.getString(view.getColumnIndex("CONTENU_ANGLAIS"));
CONTENU_ANG_DATE = view.getString(view.getColumnIndex("CONTENU_ANGLAIS_DATE"));
user.put("Contenu",CONTENU_ANG);
user.put("Date",CONTENU_ANG_DATE);
userList.add(user);
} while(view.moveToNext());
Log.d("Contenu",userList.toString());
Log.d("Date",userList.toString());
ListAdapter adapter = new SimpleAdapter(AdminEvenementActivity3.this, userList, R.layout.cdcangrow,new String[]{"Contenu", "Date"}, new int[] .
{R.id.ContenuANG, R.id.ContenuANGDate});
CDCANGList.setAdapter(adapter);
}
view.close();
db.close();
return rootView;
}
}```
Here is my layout holding the listview :
```<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/CDCANGList"/>
</RelativeLayout>```
And here is my layout for the arrangement of each row of the listview :
```<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/ContenuANG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="#+id/textView3"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/ContenuANGDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="#+id/textView7"
app:layout_constraintTop_toBottomOf="#+id/ContenuANG" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:drawableLeft="#drawable/ic_histgeo"
android:text="Travail effectuer :"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginLeft="72dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="152dp"
android:layout_marginRight="152dp"
android:text="Date : "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>```
I'm expecting each row of the table to display in the listview of my activity. I'm getting the following error message caused by the "#Override" : "error: method does not override or implement a method from a supertype".
'onCreateView() method is only for fragment it cannot be override in activity.'
put you all the code in onCreate() method of your activity. it will be working pretty fine Thanks
if you feel any other problem please discuss
Thanks you a lot for your answer! I did the modification, but now i'm having some troubles on my layout inflater and my retur rootView. Any ideas how i could correct this? See my code below.
package com.example.schoolapp.Admin;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.example.schoolapp.DBHelper;
import com.example.schoolapp.R;
import java.util.ArrayList;
import java.util.HashMap;
public class AdminEvenementActivity3 extends AppCompatActivity {
private TextView Date;
DBHelper SchoolDB;
String CONTENU_ANG;
String CONTENU_ANG_DATE;
HashMap<String,String> user;
ListView CDCANGList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_evenement3);
Date = (TextView) findViewById(R.id.Date);
Intent incomingIntent = getIntent();
String date = incomingIntent.getStringExtra("date");
Date.setText(date);
final View rootView = inflater.inflate(R.layout.fragment_cdc_ang, container, false);
CDCANGList = rootView.findViewById(R.id.CDCANGList);
SchoolDB = new DBHelper(AdminEvenementActivity3.this);
SQLiteDatabase db = SchoolDB.getReadableDatabase();
ArrayList<HashMap<String, String>> userList = new ArrayList<>();
Cursor view = db.rawQuery("SELECT CONTENU_ANGLAIS_DATE, CONTENU_ANGLAIS FROM CONTENU_COURS_ANGLAIS", null);
if (view.moveToFirst()){
do {
// Passing values
user = new HashMap<>();
CONTENU_ANG = view.getString(view.getColumnIndex("CONTENU_ANGLAIS"));
CONTENU_ANG_DATE = view.getString(view.getColumnIndex("CONTENU_ANGLAIS_DATE"));
user.put("Contenu",CONTENU_ANG);
user.put("Date",CONTENU_ANG_DATE);
userList.add(user);
} while(view.moveToNext());
Log.d("Contenu",userList.toString());
Log.d("Date",userList.toString());
ListAdapter adapter = new SimpleAdapter(AdminEvenementActivity3.this, userList, R.layout.cdcangrow,new String[]{"Contenu", "Date"}, new int[]{R.id.ContenuANG, R.id.ContenuANGDate});
CDCANGList.setAdapter(adapter);
}
view.close();
db.close();
return rootView;
}
}

How can I pass an Intent to layout which contains ListView? (Android Studio)

I am trying to pass an Intent from my mainScreen Activity class to a new android class with a layout that contains a ListView ..
MainActivityScreen Code :
(TimePassed is in the format of 'HH:MM:SS')
public void MoveToShiftsPage(View view) {
Intent shiftsIntent=new Intent(this,Shifts.class);
shiftsIntent.putExtra("time",TimePassed);
startActivity(shiftsIntent);
}
"MoveToShiftsPage" in the MainActivity.xml file :
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#mipmap/payment"
android:id="#+id/shiftbtn"
android:onClick="MoveToShiftsPage"
/>
Shifts.xml File( the layout which contains the ListView and the Intent sent to it)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainScreen"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:id="#+id/MyListView"
android:clickable="true"
style="#style/Base.Widget.AppCompat.ListView.DropDown">
</ListView>
/>
and the Shift.class which gets the Intent and it's supposed to represent the ListView with the time that passed :
import android.app.Activity;
import android.content.Intent;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.util.List;
/**
* Created by user on 19/09/2015.
*/
public class Shifts extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shifts);
Intent MyIntent=getIntent();
String TimePassed=MyIntent.getStringExtra("time");
String [] timepass=TimePassed.split(":");
ListAdapter theAdapter=new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_activated_1,timepass);
ListView thelist=(ListView)findViewById(R.id.MyListView);
thelist.setAdapter(theAdapter);
}
}
Unfortunately whenever I click on the image button which is supposed to be sent to the shift activity class and represents the layout with the ListView the app crashes ..
what should I do ?
try this one hopefully it works
Intent MyIntent=this.getIntent();

Categories