I'm trying to make a calander app following this tut:
How can I create a weekly calendar view for an Android Honeycomb application?
But i need to add a view to the corresponding RelativeLayout but every time i try to run
the app it chrashes.
My fragment .java file:
public class Calendar extends Activity {
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class FragmentCalendar extends Fragment {
public FragmentCalendar() {
RelativeLayout activeDay = (RelativeLayout)getActivity(). findViewById(R.id.sundayRelativeLayout);
View viw = new View(null);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,2);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
viw.setBackgroundColor(Color.BLUE);
viw.setLayoutParams(lay);
activeDay.addView(viw);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_calendar,
container, false);
return rootView;
}
}
My fragment_Calendar.xml
<RelativeLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.TJ.rijschool_app.Calendar"
android:orientation="vertical"
android:padding="0dp"
>
<LinearLayout
android:id="#+id/dayLabelsLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp" >
<RelativeLayout
android:id="#+id/currentMonthRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="1" >
<TextView
android:id="#+id/currentMonthTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text=""
android:textSize="15dp"
android:textStyle="bold"
android:textColor="#color/medium_dark_gray" />
<TextView
android:id="#+id/currentYearTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text=""
android:textSize="13dp"
android:textStyle="bold"
android:textColor="#color/medium_dark_gray" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/sundayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/sundayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/sundayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:text="#string/sun"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/dayMarkerView"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="#color/strong_blue" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/mondayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/mondayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/mondayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:gravity="center"
android:text="#string/mon"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tuesdayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/tuesdayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tuesdayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:text="#string/tue"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/wednesdayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/wednesdayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/wednesdayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:text="#string/wed"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/thursdayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/thursdayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/thursdayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:text="#string/thu"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/fridayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/fridayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:layout_marginLeft="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/fridayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:text="#string/fri"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/saturdayHeaderRelativeLayout"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="2" >
<TextView
android:id="#+id/saturdayDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text=""
android:textColor="#color/medium_dark_gray"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/saturdayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:text="#string/sat"
android:textColor="#color/medium_dark_gray"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
Had to delete the part about time because file was getting to big to post here.
As you can see the View called dayMarkerView has to be added dynamicly on the day it is.
Had to change:
public FragmentCalendar() {
RelativeLayout activeDay = (RelativeLayout)getActivity(). findViewById(R.id.sundayRelativeLayout);
View viw = new View(null);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,2);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
viw.setBackgroundColor(Color.BLUE);
viw.setLayoutParams(lay);
activeDay.addView(viw);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_calendar,
container, false);
return rootView;
}
TO:
public FragmentCalendar() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = new View(getActivity());
v = inflater.inflate(R.layout.fragment_calendar, container, false);
View pl = v.findViewById(R.id.thursdayHeaderRelativeLayout);
View Paper = new View(pl.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,2);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
Paper.setLayoutParams(params);
Paper.setBackgroundColor(getActivity().getColor(R.color.strong_blue));
((RelativeLayout)pl).addView(Paper);
//Zet de datum op zondag
//View tv = v.findViewById(R.id.sundayDateTextView);
//((TextView)tv).setText("13");
return v;
}
Related
I want to make a page using fragment that has a CardView. Let say I have 4 cardviews. I want the cardviews to be clickable and when clicked, they will open a new fragment with a VideoView. Can I only make one fragment that can play different video based on which cardview is clicked.
Meaning, let say, I click on cardview1, it will open a fragment with video1, then i click cardview 2, it will open from the same fragment but with video2. Is it possible to use only one fragment to have more than one videoView?
If possible how can I do that? someone please help.
this is my code
fragment_exercise.xml (fragment with cardviews)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
tools:context=".ExerciseFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical"
android:background="#FFF8DD">
<ImageView
android:id="#+id/logo2"
android:layout_width="149dp"
android:layout_height="48dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:layout_marginRight="50dp"
android:src="#drawable/logobg" />
<androidx.cardview.widget.CardView
android:id="#+id/c1"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="100dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient16"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Running"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/running" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c2"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="100dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient3"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Walking"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/walking" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c3"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="250dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient22"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Aerobics"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/aerobatic" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c4"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="250dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient13"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Yoga"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/yoga2" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c5"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="400dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient29"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Boxing"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/boxing" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c6"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="400dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient10"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Cycling"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/biking" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c7"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="550dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient24"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Dancing"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/dance" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c8"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="550dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient30"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Swimming"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/m2" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
</ScrollView>
ExerciseFragment.java
public class ExerciseFragment extends Fragment implements View.OnClickListener{
View v;
CardView cv1, cv2, cv3, cv4, cv5, cv6, cv7, cv8;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_exercise, container, false);
cv1 = (CardView) v.findViewById(R.id.c1);
cv1.setOnClickListener(this);
cv2 = (CardView) v.findViewById(R.id.c2);
cv2.setOnClickListener(this);
cv3 = (CardView) v.findViewById(R.id.c3);
cv3.setOnClickListener(this);
cv4 = (CardView) v.findViewById(R.id.c4);
cv4.setOnClickListener(this);
cv5 = (CardView) v.findViewById(R.id.c5);
cv5.setOnClickListener(this);
cv6 = (CardView) v.findViewById(R.id.c6);
cv6.setOnClickListener(this);
cv7 = (CardView) v.findViewById(R.id.c7);
cv7.setOnClickListener(this);
cv8 = (CardView) v.findViewById(R.id.c8);
cv8.setOnClickListener(this);
// Inflate the layout for this fragment
return v;
}
#Override
public void onClick(View v) {
Fragment fragment1, fragment2, fragment3, fragment4, fragment5, fragment6, fragment7, fragment8;
switch (v.getId()) {
case R.id.c1:
fragment1 = new VideoFragment();
FragmentTransaction transaction1 = getParentFragmentManager().beginTransaction();
transaction1.replace(R.id.container,fragment1);
transaction1.commit();
break;
case R.id.c2:
fragment2 = new VideoFragment();
FragmentTransaction transaction2 = getParentFragmentManager().beginTransaction();
transaction2.replace(R.id.container,fragment2);
transaction2.commit();
break;
case R.id.c3:
fragment3 = new VideoFragment();
FragmentTransaction transaction3 = getParentFragmentManager().beginTransaction();
transaction3.replace(R.id.container,fragment3);
transaction3.commit();
break;
case R.id.c4:
fragment4 = new VideoFragment();
FragmentTransaction transaction4 = getParentFragmentManager().beginTransaction();
transaction4.replace(R.id.container,fragment4);
transaction4.commit();
break;
case R.id.c5:
fragment5 = new VideoFragment();
FragmentTransaction transaction5 = getParentFragmentManager().beginTransaction();
transaction5.replace(R.id.container,fragment5);
transaction5.commit();
break;
case R.id.c6:
fragment6 = new VideoFragment();
FragmentTransaction transaction6 = getParentFragmentManager().beginTransaction();
transaction6.replace(R.id.container,fragment6);
transaction6.commit();
break;
case R.id.c7:
fragment7 = new VideoFragment();
FragmentTransaction transaction7 = getParentFragmentManager().beginTransaction();
transaction7.replace(R.id.container,fragment7);
transaction7.commit();
break;
case R.id.c8:
fragment8 = new VideoFragment();
FragmentTransaction transaction8 = getParentFragmentManager().beginTransaction();
transaction8.replace(R.id.container,fragment8);
transaction8.commit();
break;
}
}
}
fragment_video.xml (fragment with videoview)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".VideoFragment">
<VideoView
android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
</FrameLayout>
VideoFragment.java
this is what i have for now
public class VideoFragment extends Fragment {
View v;
VideoView view;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = (VideoView) v.findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(view);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/raw/boxing.mp4");
view.setMediaController(mediaController);
view.setVideoURI(uri);
view.requestFocus();
view.start();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_exercise, container, false);
return v;
}
}
this code has error at line:
MediaController mediaController = new MediaController(this);
please help, how do i make one fragment that will play different videos based on the clicked cardviews without having to make multiple fragments. Is it possible, if yes please help write the code for me. Thank you so much.
I have recyclerview with many items. And this is a screenshot of my application, showing the first item of my recyclerview.
pict of my page
but when I change the choice of the fifth item, the choice of the first item is changing too. Any idea why this is happening? And what should I do?
this is my adapter:
public class SkoringAdapter extends RecyclerView.Adapter<SkoringAdapter.SkoringViewHolder>{
private List<Skoring> skoringList;
private Context context;
public SkoringAdapter(final Context context) {
this.skoringList = new ArrayList<>();
this.context = context;
}
public void setSkoringList(List<Skoring> skoringList){
this.skoringList.clear();
this.skoringList.addAll(skoringList);
notifyDataSetChanged();
}
static class SkoringViewHolder extends RecyclerView.ViewHolder{
Context context;
TextView tvSoal, tvKe, tvTotal, tvProses;
RadioGroup rgPilihan;
RadioButton rb1, rb2, rb3, rb4, rb5, rb6;
SkoringViewHolder(View itemView, final Context context) {
super(itemView);
this.context = context;
tvSoal = itemView.findViewById(R.id.tvSoal);
...etc
}
}
#NonNull
#Override
public SkoringViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_skoring, parent, false);
return new SkoringViewHolder(itemView,context);
}
#Override
public void onBindViewHolder(#NonNull final SkoringViewHolder holder, final int position) {
final Skoring tg = skoringList.get(position);
holder.tvSoal.setText(tg.getSoal());
holder.tvKe.setText(Integer.toString(position + 1));
holder.tvTotal.setText(Integer.toString(skoringList.size()));
holder.rgPilihan.setVisibility(View.GONE);
holder.rb1.setVisibility(View.GONE);
holder.rb2.setVisibility(View.GONE);
holder.rb3.setVisibility(View.GONE);
holder.rb4.setVisibility(View.GONE);
holder.rb5.setVisibility(View.GONE);
holder.rb6.setVisibility(View.GONE);
String[] kunci = tg.getKunci().split("`");
String[] pilihan = new String[kunci.length];
String[] isi = new String[kunci.length];
String[] skor = new String[kunci.length];
for (int i=0; i<kunci.length; i++){
String[] pisah = kunci[i].split("~");
if(pisah.length == 3){
pilihan[i] = pisah[0]; isi[i] = pisah[1]; skor[i] = pisah[2];
}
}
holder.rgPilihan.setVisibility(View.VISIBLE);
if(kunci.length > 0){
holder.rb1.setText(isi[0]);
holder.rb1.setVisibility(View.VISIBLE);
if(kunci.length > 1){
holder.rb2.setText(isi[1]);
holder.rb2.setVisibility(View.VISIBLE);
if(kunci.length > 2){
holder.rb3.setText(isi[2]);
holder.rb3.setVisibility(View.VISIBLE);
if(kunci.length > 3){
holder.rb4.setText(isi[3]);
holder.rb4.setVisibility(View.VISIBLE);
if(kunci.length > 4){
holder.rb5.setText(isi[4]);
holder.rb5.setVisibility(View.VISIBLE);
if(kunci.length > 5){
holder.rb6.setText(isi[5]);
holder.rb6.setVisibility(View.VISIBLE);
}}}}}}}}
And this is my item_skoring.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_margin="16dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="16dp">
<TextView
android:id="#+id/tvSoal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:layout_gravity="center"
android:textAlignment="center"
android:textColor="#color/colorBlack"
android:textSize="17sp"
android:layout_marginBottom="16dp"/>
<RadioGroup
android:visibility="visible"
android:id="#+id/rgPilihan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<RadioButton
android:id="#+id/rb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:visibility="gone"
android:buttonTint="#color/colorPrimary"/>
<RadioButton
android:textSize="16sp"
android:visibility="gone"
android:id="#+id/rb2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"/>
<RadioButton
android:textSize="16sp"
android:visibility="gone"
android:id="#+id/rb3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"/>
<RadioButton
android:textSize="16sp"
android:visibility="gone"
android:id="#+id/rb4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"/>
<RadioButton
android:textSize="16sp"
android:visibility="gone"
android:id="#+id/rb5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"/>
<RadioButton
android:textSize="16sp"
android:visibility="gone"
android:id="#+id/rb6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"/>
</RadioGroup>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tiTelp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:hint="No. Telepon"
android:id="#+id/etTelp"
android:drawablePadding="5dp"
android:layout_weight="0.85" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tiHP"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:hint="No. Handphone"
android:id="#+id/etHP"
android:drawablePadding="5dp"
android:layout_weight="0.85"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tiEmail"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:hint="Alamat Email"
android:id="#+id/etEmail"
android:drawablePadding="5dp"
android:layout_weight="0.85"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tiNPWP"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:hint="No. NPWP"
android:id="#+id/etNPWP"
android:drawablePadding="5dp"
android:layout_weight="0.85"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:padding="10dp"
android:background="#color/colorGreyUp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data ke "
android:textStyle="italic"
android:textColor="#color/colorBlack"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvKe"
android:textStyle="italic|bold"
android:textColor="#color/colorBlack"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" dari "
android:textStyle="italic"
android:textColor="#color/colorBlack"/>
<TextView
android:id="#+id/tvTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic|bold"
android:textColor="#color/colorBlack"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" data"
android:textStyle="italic"
android:textColor="#color/colorBlack"/>
</LinearLayout>
<TextView
android:background="#color/colorPrimary"
android:textColor="#color/colorWhite"
android:visibility="gone"
android:padding="14dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SELANJUTNYA"
android:textSize="18sp"
android:clickable="true"
android:id="#+id/bProses"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Solved with adding this on my java class:
MyrecyclerView.setItemViewCacheSize(100);
I have two radiobutton groups that need to be initialized when loading the screen, so I used this code:
mVisibilityPublic.setChecked(true);
But when I load the screen I get the following (first is the wrong behavior, second is the expected one):
I've tried with all these:
mVisibilityPublic.setSelected(true);
mVisibilityPublic.performClick();
mVisibilityPublic.setActivated(true);
mVisibilityPublic.invalidate();
mVisibilityPublic.requestLayout();
But I get the same result.
<ScrollView 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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="#dimen/form_vertical_spacing"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".createevent.CreateEventActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#string/create_event_privacy"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/create_visibility_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/createevent_visibility_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_public_event"/>
<RadioButton
android:id="#+id/createevent_visibility_private"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_private_event"/>
<RadioButton
android:id="#+id/createevent_visibility_ppv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv"/>
</RadioGroup>
<LinearLayout
android:id="#+id/ppv_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/create_event_ppv_section"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.currency.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.myapp.ui.AutoCompleteCombo
android:id="#+id/ppv.currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_currency">
</com.myapp.ui.AutoCompleteCombo>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.price.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="#+id/ppv.price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_price"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RadioGroup
android:id="#+id/ppv_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/ppv_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_allcountries"/>
<RadioButton
android:id="#+id/ppv_allexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_except"/>
<RadioButton
android:id="#+id/ppv_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_some"/>
</RadioGroup>
<com.myapp.countries.CountriesMultiCombo
android:id="#+id/create.ppv.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout>
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/general_info"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="-32dp"
android:layout_marginRight="-32dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#color/colorDivider"
/>
<LinearLayout
android:id="#+id/geoblock_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/geo_blocking_settings_title"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/geo_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/geo_none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_none"/>
<RadioButton
android:id="#+id/geo_blockonly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_only"/>
<RadioButton
android:id="#+id/geo_blockexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_all_except"/>
</RadioGroup>
<com.myapp.createevent.countries.CountriesMultiCombo
android:id="#+id/create.geo.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout> <Button
android:id="#+id/test_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLICK ME"/>
</LinearLayout>
</ScrollView>
Note that if I select the option manually (like I did with the second example in the image) I get the proper result. Its only if I do it programmatically that its missing the inner circle.
public class TestFragment extends Fragment {
private Unbinder mUnbinder;
#BindView(R.id.createevent_visibility_public)
RadioButton mVisibilityPublic;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragment_advanced_opts, container, false);
mUnbinder = ButterKnife.bind(this, inflate);
return inflate;
}
public static TestFragment newInstance(int tvId, int eventId) {
TestFragment testFragment = new TestFragment();
Bundle args = new Bundle();
args.putInt(TV_ARGUMENT, tvId);
args.putInt(EVENTID_ARGUMENT, eventId);
testFragment.setArguments(args);
return testFragment;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mVisibilityPublic.setChecked(true);
}
}
Strangely, my listView's onClick no longer works after I added two Buttons: Submit and Show Result.
Here is the list view xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".CulturalActivity"
android:background="#EFEFEF"
android:id="#+id/AdLayout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#android:color/transparent"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
Here is the layout of each list row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:background="#drawable/bg_card"
android:orientation="horizontal"
android:padding="5dip" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="-60dp"
android:background="#2093CD"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="52dp"
android:text="Audit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout2" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Farm/Grp"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignTop="#+id/tile"
android:layout_toRightOf="#+id/textView4" />
<!--thumbnail-->
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/thumbnail_image"
android:layout_marginTop="35dp"
android:gravity="center"
android:id="#+id/tile">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="50dp"
android:clickable="false"
android:layout_height="50dp"
android:src="#drawable/opened" />
</LinearLayout>
<TextView
android:id="#+id/crophead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignBottom="#+id/tile"
android:layout_alignLeft="#+id/title" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Certification"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/certification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/title"
android:text="Test"
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Audit Type"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/tile"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/audittype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/certification"
android:maxLines="2"
android:text="ES"
android:textColor="#343434"
android:textSize="17sp" />
<View
android:layout_width="fill_parent"
android:layout_height="3px"
android:layout_marginTop="200dp"
android:background="#21265b"
android:id="#+id/view" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/view"
android:layout_alignLeft="#+id/view"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="false" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_alignTop="#+id/textView6"
android:layout_alignRight="#+id/startdate" />
<TextView
android:id="#+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="30/05/1992"
android:textSize="17sp"
android:layout_alignTop="#+id/enddate"
android:layout_toRightOf="#+id/relativeLayout2"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="2/13/14"
android:textSize="17sp"
android:id="#+id/enddate"
android:layout_below="#+id/textView7"
android:layout_alignRight="#+id/textView7" />
<TextView
android:id="#+id/farm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/audittype"
android:maxLines="3"
android:layout_alignTop="#+id/title"
android:text="Tea Estate Nagarcoil Tamil Nadu, India "
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/crop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/farm"
android:layout_alignTop="#+id/crophead"
android:maxLines="2"
android:text="Wheat without its chaff and barn but not brown"
android:textColor="#343434"
android:textSize="17sp" />
<Button
android:id="#+id/upsync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/blue_thumb"
android:layout_below="#+id/enddate"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Show Results"
android:textColor="#android:color/white" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/upsync"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_below="#+id/enddate"
android:background="#drawable/blue_thumb"
android:text="Submit"
android:textColor="#android:color/white" />
</RelativeLayout>
Here is the click snippet of the list view:
listview.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
long audit_id;
try{
audit_id = (new CustomListAdapter(HomeList.this, c).getAuditID(position));
changeTileStatus(audit_id,"opened");
System.out.println("listClicked");
sendAuditAndIntent(audit_id);
}catch(Exception e)
{
System.out.println("ERROR # HOMELIST list onClick: "+e);
}
}
private void sendAuditAndIntent(long audit_id) { //sends audit id and api key
Intent intent = new Intent(HomeList.this,ChapterActivity.class );
Bundle extras= new Bundle();
extras.putString("audit_id",String.valueOf(audit_id));
extras.putString("api_key", api_key);
intent.putExtras(extras);
startActivity(intent);
}
private void changeTileStatus(long audit_id, String value) {
AuditTableManager tile= new AuditTableManager(HomeList.this);
tile.open();
tile.updateEntry(audit_id, value);
tile.close();
}
});
OnItemClickListener is not called if cells contain clickable Views. It is an Android feature. You can handle clicks by OnClickListener then - set it to your two buttons (not the listView itself).
In your adapter:
public View onCreateView(..., final int position){
...
convertView.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction1(position);
}
});
convertView.findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction2(position);
}
});
...
}
Try android:Focusable="false" and also android:clickable="false" in the custom row TextView
I am making some changes to an XML layout side of my application. There is a ImageView I am trying to bring to the front yet when I do the app crashes and I can seem to tell why.
Working XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/place_distance"
android:layout_width="wrap_content"
android:layout_height="14dip"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_margin="5dip"
android:gravity="right"
android:text="28-12-1920 22:22"
android:textColor="#color/white"
android:textSize="12sp" />
<ImageView
android:id="#+id/place_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:scaleType="centerCrop"
android:src="#drawable/icon_4860_1" />
<LinearLayout
android:id="#+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/place_img"
android:layout_alignRight="#+id/place_distance"
android:layout_below="#+id/place_distance"
android:layout_marginTop="5dp"
android:background="#drawable/chatbox" >
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="43dp"
android:padding="9dp"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="#android:color/white"
android:textColorLink="#android:color/holo_blue_dark"
android:textIsSelectable="true" />
</LinearLayout>
<TextView
android:id="#+id/place_name"
android:textIsSelectable="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/place_distance"
android:layout_toLeftOf="#+id/place_distance"
android:layout_toRightOf="#+id/place_img"
android:text="Tweeked"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/gray"
android:textSize="11dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/pe_profile_pic"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_margin="2dp"
android:layout_alignBottom="#+id/place_img"
android:layout_alignRight="#+id/place_img"
android:src="#drawable/offline" />
XML that crashes:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/place_distance"
android:layout_width="wrap_content"
android:layout_height="14dip"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_margin="5dip"
android:gravity="right"
android:text="28-12-1920 22:22"
android:textColor="#color/white"
android:textSize="12sp" />
<LinearLayout
android:id="#+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/place_img"
android:layout_alignRight="#+id/place_distance"
android:layout_below="#+id/place_distance"
android:layout_marginTop="5dp"
android:background="#drawable/chatbox" >
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="43dp"
android:padding="9dp"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="#android:color/white"
android:textColorLink="#android:color/holo_blue_dark"
android:textIsSelectable="true" />
<!-- android:autoLink="web|all" -->
</LinearLayout>
<ImageView
android:id="#+id/place_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:scaleType="centerCrop"
android:src="#drawable/icon_4860_1" />
<TextView
android:id="#+id/place_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/place_distance"
android:layout_toLeftOf="#+id/place_distance"
android:text="Tweeked"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/gray"
android:textIsSelectable="true"
android:textSize="11dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/pe_profile_pic"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignBottom="#+id/place_img"
android:layout_alignRight="#+id/place_img"
android:layout_margin="2dp"
android:src="#drawable/offline" />
Im just trying to bring the #place_img to the front of the #wrapper.
java.lang.NullPointerException
at com.peekatucorp.peekatu.DiscussArrayAdapter.getView(DiscussArrayAdapter.java:172)
DiscussArrayAdapter.java:
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(type==1 || type==3)
row = inflater.inflate(R.layout.listitem_discuss, parent, false);
else if(type==4 || type==5)
row = inflater.inflate(R.layout.listitem_users, parent, false);
else
row = inflater.inflate(R.layout.listitem_messages, parent, false);
}
//
final OneComment coment = getItem(position);
userComment = (TextView) row.findViewById(R.id.comment);
userImage = (ImageView) row.findViewById(R.id.place_img);
userName = (TextView) row.findViewById(R.id.place_name);
userOnlineImage = (ImageView) row.findViewById(R.id.pe_profile_pic);
commentDate = (TextView) row.findViewById(R.id.place_distance);
userComment.setText(coment.comment);
ImageLoader imageLoader = ImageLoader.getInstance();
// imageLoader = ImageLoader.getInstance();
// imageLoader.init(ImageLoaderConfiguration.createDefault(convertView.getContext()));
imageLoader.displayImage(coment.image, userImage);
userImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// it was the 1st button
final TabInfo tab = navact.getCurrentTabInfo();
final ProfileFragment fragment = new ProfileFragment().setUser(coment.userid).setNAV(navact);
// fragment.setText(characters[position]);
// second, you push the fragment. It becomes visible and the up button is
// shown
navact.pushFragment(tab, fragment);
/*
Intent i = new Intent(context, ProfileActivity.class);
i.putExtra("userID", coment.userid);
// Create the view using FirstGroup's LocalActivityManager
View view = ChatTabGroup.group.getLocalActivityManager()
.startActivity("show profile", i
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
ChatTabGroup.group.replaceView(view);*/
}
});
if(coment.online.equalsIgnoreCase("1"))
userOnlineImage.setImageResource(R.drawable.online);
else
userOnlineImage.setImageResource(R.drawable.offline);
if(coment.gender.equalsIgnoreCase("M"))
userName.setTextColor(Color.parseColor("#878ff4"));
else if(coment.gender.equalsIgnoreCase("F"))
userName.setTextColor(Color.parseColor("#f487d6"));
else
userName.setTextColor(Color.parseColor("#969696"));
userName.setText(coment.username);
commentDate.setText(coment.time);
if(type==4){
commentDate = (TextView) row.findViewById(R.id.textView1);
SharedPreferences preferences = getContext().getSharedPreferences("MyPreferences", getContext().MODE_PRIVATE);
double distance = distFrom(Double.parseDouble(getItem(position).time.split(",")[0]),Double.parseDouble(getItem(position).time.split(",")[1]),
Double.parseDouble(preferences.getString("user_lat", "0.0")),Double.parseDouble(preferences.getString("user_lng", "0.0"))
);
commentDate.setText(""+String.format("%.2f", (distance*0.62))+"miles");
}
if(type==1 || type==3){
wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);
}else{
}
//
return row;
}
Thank you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/place_distance"
android:layout_width="wrap_content"
android:layout_height="14dip"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_margin="5dip"
android:gravity="right"
android:text="28-12-1920 22:22"
android:textColor="#color/white"
android:textSize="12sp" />
<LinearLayout
android:id="#+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/place_img"
android:layout_alignRight="#+id/place_distance"
android:layout_below="#+id/place_distance"
android:layout_marginTop="5dp"
android:background="#drawable/chatbox" >
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="43dp"
android:padding="9dp"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="#android:color/white"
android:textColorLink="#android:color/holo_blue_dark"
android:textIsSelectable="true"
android:typeface="serif"
android:autoLink="web|all"
/>
<!-- android:autoLink="web|all" -->
</LinearLayout>
<ImageView
android:id="#+id/place_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:scaleType="centerCrop"
android:src="#drawable/icon_4860_1" />
<ImageView
android:id="#+id/pe_profile_pic"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignBottom="#+id/place_img"
android:layout_alignRight="#+id/place_img"
android:layout_margin="2dp"
android:src="#drawable/offline" />
<TextView
android:id="#+id/place_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/wrapper"
android:layout_toRightOf="#+id/place_img"
android:text="Tweeked"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/gray"
android:textIsSelectable="true"
android:textSize="14sp"
android:textStyle="bold"
android:typeface="normal" />