I can't see correct data on my Coordinator Layout: I mean, my layout seems correctly set and my java class is correct too.
But when I launch my application I don't see error but my activity have TextView, Image and WebView not initialized with passed data.
I tried to inflate all content with traditional
(TextView) findViewById(R.id.my_id) and with butterknife.ButterKnife library, same result.
Here my activity
public class EventDetailsActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleMap.OnMapClickListener {
private long eventID;
private String eventTitle;
private String eventDesc;
private String eventDate;
private String eventTime;
private String eventImageUrl;
private String eventAddress;
private Double lat;
private Double lng;
private int maxBookings;
#InjectView(R.id.event_title) TextView eventTitleTv;
#InjectView(R.id.event_address) TextView eventAddressTv;
#InjectView(R.id.event_start_date) TextView eventDateTv;
#InjectView(R.id.event_start_time) TextView eventTimeTv;
#InjectView(R.id.event_image) ImageView imageEventView;
#InjectView(R.id.map_address) TextView evetMapAddress;
#InjectView(R.id.event_desc) WebView mWebView;
#InjectView(R.id.toolbar) Toolbar toolbar;
#InjectView(R.id.collapsing_toolbar) CollapsingToolbarLayout collapsingToolbarLayout;
#InjectView(R.id.btnJoin) AppCompatButton btnJoin;
#InjectView(R.id.open_map_button) FloatingActionButton openMapButton;
private MapFragment googleMap;
private GoogleMap map;
private Event event;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivityTransitions();
setContentView(R.layout.event_details_activity);
ButterKnife.inject(this);
btnJoin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showDialogPlus();
}
});
openMapButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openMapDetail();
}
});
try {
inizializeToolbar();
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
event = extras == null ? null : (Event) extras.getSerializable(Const.EVENT_OBJECT);
} else {
event = (Event) savedInstanceState.getSerializable(Const.EVENT_OBJECT);
}
eventTitle = event.getEventName();
eventDesc = event.getEventContent();
eventDate = event.getEventStartDate();
eventTime = event.getEventStartTime();
eventImageUrl = event.getEventImageUrl();
lat = event.getLocationLatitude();
lng = event.getLocationLongitude();
eventAddress = event.getLocationAddress();
eventID = event.getEventId();
maxBookings = 10;
Log.d("EVENT", "__event title " + eventTitle);
Log.d("EVENT", "__event eventDesc " + eventDesc);
Log.d("EVENT", "__event eventDate " + eventDate);
Log.d("EVENT", "__event eventTime " + eventTime);
Log.d("EVENT", "__event eventImageUrl " + eventImageUrl);
Log.d("EVENT", "__event lat " + lat);
Log.d("EVENT", "__event lng " + lng);
Log.d("EVENT", "__event eventAddress " + eventAddress);
Log.d("EVENT", "__event eventTitle " + eventTitle);
Log.d("EVENT", "__event evv name " + event.getEventName());
initializeMap();
loadImage();
loadTextViews();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initActivityTransitions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide transition = new Slide();
transition.excludeTarget(android.R.id.statusBarBackground, true);
getWindow().setEnterTransition(transition);
getWindow().setReturnTransition(transition);
}
}
private void inizializeToolbar() {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
collapsingToolbarLayout.setTitle(eventTitle);
collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);
collapsingToolbarLayout.setExpandedTitleColor(Color.TRANSPARENT);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
private void loadTextViews(){
eventTitleTv.setText("TITOLO DELL'EVENTO");
eventAddressTv.setText(eventAddress);
evetMapAddress.setText(eventAddress + " -> ");
setEventDesc();
eventDateTv.setText(Utils.getDateFromString(eventDate));
eventTimeTv.setText(Utils.getTimeFromString(eventTime));
}
private void loadImage(){
final ProgressBar progressView = (ProgressBar) findViewById(R.id.loader);
progressView.getIndeterminateDrawable().setColorFilter(getApplicationContext().getResources().getColor(R.color.ColorPrimary), android.graphics.PorterDuff.Mode.MULTIPLY);
Picasso.with(getApplicationContext())
.load(eventImageUrl)
.fit().centerCrop()
.placeholder(R.drawable.event_placeholder_grey_2)
.into(imageEventView, new Callback() {
#Override
public void onSuccess() {
progressView.setVisibility(View.GONE);
}
#Override
public void onError() {
progressView.setVisibility(View.GONE);
}
});
}
private void showDialogPlus() {
Holder holder = new ViewHolder(R.layout.event_prenotation);
OnClickListener clickListener = new OnClickListener() {
#Override
public void onClick(DialogPlus dialog, View view) {
Spinner mySpinner=(Spinner) dialog.getHolderView().findViewById(R.id.spinner);
String bookValue = mySpinner.getSelectedItem().toString();;
int numberPerson = Integer.parseInt(bookValue);
switch (view.getId()) {
case R.id.btnJoin:
Intent intent = new Intent(getApplicationContext(), ConfirmPrenotationActivity.class);
Bundle bun = new Bundle();
bun.putInt(Const.NUMBER_PRENOT, numberPerson);
bun.putString(Const.EVENT_TITLE, eventTitle);
bun.putLong(Const.EVENT_ID, eventID);
bun.putSerializable(Const.EVENT_OBJECT, event);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(bun);
getApplicationContext().startActivity(intent);
break;
}
//dialog.dismiss();
}
};
OnItemClickListener itemClickListener = new OnItemClickListener() {
#Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
//TextView textView = (TextView) view.findViewById(R.id.text_view);
//String clickedAppName = textView.getText().toString();
// dialog.dismiss();
// Toast.makeText(MainActivity.this, clickedAppName + " clicked", Toast.LENGTH_LONG).show();
}
};
OnDismissListener dismissListener = new OnDismissListener() {
#Override
public void onDismiss(DialogPlus dialog) {
// Toast.makeText(MainActivity.this, "dismiss listener invoked!", Toast.LENGTH_SHORT).show();
}
};
OnCancelListener cancelListener = new OnCancelListener() {
#Override
public void onCancel(DialogPlus dialog) {
// Toast.makeText(MainActivity.this, "cancel listener invoked!", Toast.LENGTH_SHORT).show();
}
};
final DialogPlus dialog = DialogPlus.newDialog(this)
.setContentHolder(holder)
.setCancelable(true)
.setGravity(Gravity.BOTTOM)
.setOnClickListener(clickListener)
.setOnItemClickListener(new OnItemClickListener() {
#Override public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
Log.d("DialogPlus", "onItemClick() called with: " + "item = [" +
item + "], position = [" + position + "]");
}
})
.setOnDismissListener(dismissListener)
//.setExpanded(expanded)
//.setContentWidth(800)
.setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
.setOnCancelListener(cancelListener)
.setOverlayBackgroundResource(android.R.color.transparent)
//.setContentBackgroundResource(R.drawable.corner_background)
//.setOutMostMargin(0, 100, 0, 0)
.create();
Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner);
initializeSpinner(spinner);
dialog.show();
}
public void initializeSpinner(Spinner spin){
ArrayList<String> options = new ArrayList<String>();
for(int i=1; i<= maxBookings; i++){
options.add(""+i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_style, options) {
public View getView(int position, View convertView,ViewGroup parent) {
View v = super.getView(position, convertView, parent);
((TextView) v).setTextSize(18);
return v;
}
public View getDropDownView(int position, View convertView,ViewGroup parent) {
View v = super.getDropDownView(position, convertView,parent);
//((TextView) v).setGravity(Gravity.CENTER);
return v;
}
};
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
}
public void setEventDesc(){
mWebView.setBackgroundColor(Color.TRANSPARENT);
StringBuilder sb = new StringBuilder();
sb.append("<html><body>");
sb.append("<p align=\"justify\">");
sb.append(eventDesc);
sb.append("</p>");
sb.append("</body></html>");
//mWebView.loadData(sb.toString(), "text/html", "utf-8");
mWebView.loadData(sb.toString(), "text/html; charset=utf-8", "utf-8");
}
#TargetApi(Build.VERSION_CODES.M)
public void initializeMap() {
if (googleMap == null) {
googleMap = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
googleMap.getMapAsync(this);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_event_details, menu);
return true;
}
#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();
switch (id) {
case R.id.share_button:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, getEventInfoToShare());
startActivity(Intent.createChooser(shareIntent, "Share link using"));
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
}
}
private String getEventInfoToShare(){
StringBuilder infoEvent = new StringBuilder();
infoEvent.append("Ciao, vorrei consigliarti un evento :-)");
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventTitle);
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventAddress);
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventDesc.substring(0, Math.min(eventDesc.length(), 200)));
infoEvent.append("...continua");
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append("Visita -> www.dayroma.it");
return infoEvent.toString();
}
#Override
public void onBackPressed() {
finish();
super.onBackPressed();
}
#Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setOnMapClickListener(this);
googleMap.getUiSettings().setScrollGesturesEnabled(false);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 15.0f));
map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng))
.title(eventTitle));
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
openMapDetail();
return true;
}
});
}
public void openMapDetail(){
Intent i = new Intent(getApplicationContext(), MapsDetailActivity.class);
Bundle bun = new Bundle();
bun.putDouble(Const.EVENT_LAT, lat);
bun.putDouble(Const.EVENT_LONG, lng);
bun.putString(Const.EVENT_TITLE, eventTitle);
bun.putString(Const.EVENT_ADDRESS, eventAddress);
bun.putString(Const.EVENT_IMG_LINK, eventImageUrl);
bun.putSerializable(Const.EVENT_OBJECT, event);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtras(bun);
getApplicationContext().startActivity(i);
}
#Override
public void onMapClick(LatLng latLng) {
openMapDetail();
}
}
And here the layout:
<android.support.design.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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/image_event_detail_height"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/ColorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true"
>
<util.SquareImageView
android:id="#+id/event_image"
android:layout_width="match_parent"
android:layout_height="#dimen/image_event_detail_height"
android:maxHeight="#dimen/image_event_detail_height"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!--<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ProgressBar
android:id="#+id/loader"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_gravity="center"
android:indeterminate="true"
android:layout_centerInParent="true"
/>
</RelativeLayout>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#drawable/google_cards_background_bottom"
android:gravity="left"
android:orientation="vertical" >
<!-- Titolo Evento -->
<TextView
android:id="#+id/event_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:text="Eat at Joe"
android:textColor="#color/ColorPrimary"
android:textSize="18sp"
/>
<!-- indirizzo -->
<TextView
android:id="#+id/event_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="9dp"
android:layout_marginBottom="1dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/ic_position_black_18dp"
android:drawablePadding="2dip"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="left"
android:orientation="horizontal" >
<!-- data inizio evento-->
<TextView
android:id="#+id/event_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/calendar_black_18dp"
android:drawablePadding="2dip"
/>
<!-- ora inizio evento-->
<TextView
android:id="#+id/event_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="3dp"
android:layout_marginBottom="20dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/clock_18dp"
android:drawablePadding="2dip"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
</LinearLayout>
<!-- DETTAGLI -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/rounded_shape"
>
<TextView
android:id="#+id/event_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="3dp"
android:background="#android:color/transparent"
android:text="Dettagli"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="17sp"
android:gravity="center"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >
<WebView
android:id="#+id/event_desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hardwareAccelerated="true"
/>
</ScrollView>
</LinearLayout>
<!-- FINE DETTAGLI -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:foreground="#color/dark_trasparent"
>
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="#dimen/map_height"
map:cameraTargetLat="41.890122"
map:cameraTargetLng="12.494248"
map:cameraTilt="30"
map:cameraZoom="15"
tools:ignore="MissingPrefix"
android:clickable="false"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- Maps Address -->
<TextView
android:id="#+id/map_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="22dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#android:color/transparent"
android:text="via Cristoforo Colombo 24"
android:textColor="#color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/ic_position_white_18dp"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/open_map_button"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="#color/ColorPrimary"
android:tint="#color/cpb_grey"
android:src="#drawable/navigation_black_24dp"
style="#style/floatButtonStyle"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true"
android:background="#00ffffff"
>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btnJoin"
android:background="#drawable/rounded_button_red"
android:layout_width="fill_parent"
android:textSize="17dp"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_height="#dimen/fixed_bottom_button_height"
android:layout_margin="10dp"
android:layout_centerHorizontal="true"
android:text="#string/join_event"
/>
</LinearLayout>
</RelativeLayout>
It seems a simple problem but I've never had like this before: here a screenshot of my activity, it should be visualize an event details.
Screenshot Activity
This activity is opened when a user click on an event and is fill with event data: data are correctly set because I can see all from log.
I really don't understand why TextViews, ImageView and other element are not filled with data.
Thank you for help
I can't see any closing tag for Coordinator layout in your xml file. If you haven't missed it in question then probably that is the reason for this strange behavior.
Add this at the end of your xml code and things should work better.
</android.support.design.widget.CoordinatorLayout>
Or, if that is just the mistake in question then please update your question. Whatever it is do let me know.
Related
I have an FragmentActivity which contain WebView, Edittext1, Edittext2, Checkboxes and button. When I click the button in fragment it will move to Results_activity. And if I click button from Results_activity it move back to FragmentActivity.
But my edittext values getting cleared while moving back.
FragmentActivity 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:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:id="#+id/questionContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<WebView
android:id="#+id/questionWV"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/ansA_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<EditText
android:id="#+id/ansA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="true"
android:hint="Enter answer here..."
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/ansB_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<EditText
android:id="#+id/ansB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="true"
android:hint="Enter answer here..."
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/answers_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<RelativeLayout
android:id="#+id/answer_a_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="0"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta A"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_b_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_marginStart="15dp"
android:hint="1"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta B"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_c_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="2"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta C"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_d_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="3"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta D"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center"
android:orientation="horizontal"
android:paddingBottom="30dp">
<Button
android:id="#+id/btnFinishTest"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testbutton"
android:onClick="FinishTest"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Finish Test" />
<Button
android:id="#+id/btnAnswer"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testbutton"
android:onClick="SubmitAnswer"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Submit Answer" />
</LinearLayout>
</LinearLayout>
Fragment Code
my edittexts are et1 and et2
public class QuestionFragment2018ii extends Fragment {
LinearLayout answersContainer;
int currentPageNr;
private String input1;
#Override
public View onCreateView(LayoutInflater lInflater, ViewGroup container,Bundle saveInstanceState){
currentPageNr = getArguments().getInt("position");
//initialize some variables
final Question2018ii currentQuestion2018ii = MyServerData2018ii.getInstance().getQuestion(currentPageNr);
View rootView = lInflater.inflate(R.layout.quiz_activity_fragment,container,false);
//initialize show answer option
final String ans = currentQuestion2018ii.getExplanationText();
final EditText et1 = rootView.findViewById(R.id.ansA);
final EditText et2 = rootView.findViewById(R.id.ansB);
if(MyServerData2018ii.getInstance().getTestState().equals("finished") ){
et1.setText("Your Response: " + et.getText());
et2.setText("Correct Answer: " + ans);
}
//initialize Explanation option
//initialize answers
answersContainer = (LinearLayout)rootView.findViewById(R.id.answers_container);
String[] answers = currentQuestion2018ii.getAllAnswersText();
for (int i = 0; i < answersContainer.getChildCount(); i++) {
RelativeLayout checkboxContainer = (RelativeLayout)answersContainer.getChildAt(i);
CheckBox cb = (CheckBox)checkboxContainer.getChildAt(0);
cb.setMovementMethod(new ScrollingMovementMethod());
cb.setText(answers[i]);
cb.setChecked(currentQuestion2018ii.isChecked(i));
if(MyServerData2018ii.getInstance().getTestState().equals("finished") ){
cb.setEnabled(false);
questionWebView.loadUrl("file:///android_asset/" + currentQuestion2018ii.getSolutionText());
//check if answer is right or wrong
if(currentQuestion2018ii.isCorrectAnswer(i)){
cb.setTextColor(Color.parseColor("#4DAD47"));
cb.setTypeface(null, Typeface.BOLD);
} else {
cb.setTextColor(Color.parseColor("#CE0B0B"));
}
}else{
cb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CheckBox cb = ((CheckBox) v);
int number = Integer.parseInt(cb.getHint().toString());
currentQuestion2018ii.setChecked(number, cb.isChecked());
}
});
}
}
return rootView;
}
}
ResultsActivity xml
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="30dp"
android:text="#string/results"
android:textColor="#4DAD47"
android:textSize="20sp"
android:textStyle="bold|italic" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="30dp" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="#string/correct_answers" />
</LinearLayout>
<TextView
android:id="#+id/myTotalAnswers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:paddingRight="5dp"
android:text="50/100" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainContainer"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<Button
android:id="#+id/check_results"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/testbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/check_results" />
<Button
android:id="#+id/btnMainMenu"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/testbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/main_menu" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Quiz activity
public class QuizActivity2018ii extends AppCompatActivity {
Spinner spinCategory;
EditText questionNr;
ArrayList<String> allCategories;
int totalQuestions;
AlertDialog dialog;
ViewPager pager;
QuestionPagerAdapter2018ii pagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quiz_activity_view_pager);
allCategories = new ArrayList<>(MyServerData2018ii.getInstance().getCategoryList());
totalQuestions = MyServerData2018ii.getInstance().getTotalQuestions();
//initialize category spinner
ArrayAdapter<String> categoryAdapter = new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item,allCategories);
spinCategory = (Spinner) findViewById(R.id.category);
spinCategory.setAdapter(categoryAdapter);
spinCategory.setSelection(0);
//set Category spinner callback
spinCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String currentQuestionRealCategory = MyServerData2018ii.getInstance().getQuestionCategory(pager.getCurrentItem());
String selectedCategory = spinCategory.getItemAtPosition(position).toString();
if (!selectedCategory.equals(currentQuestionRealCategory)) {
int firstQuestionNumberFromCategory = MyServerData2018ii.getInstance().getFirstQuestionNumberFromCategory(selectedCategory);
ViewPager pager = (ViewPager) findViewById(R.id.qPager);
pager.setCurrentItem(firstQuestionNumberFromCategory, false);
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//initialize number
questionNr = (EditText) findViewById(R.id.dialog_question_number);
questionNr.clearFocus();
//set number callbacks
questionNr.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_ENTER)) {
v.clearFocus();
CharSequence s = questionNr.getText();
if (!s.toString().isEmpty()) {
Integer questionNumber = Integer.parseInt(s.toString());
//avoids out of range indexes
if (questionNumber > totalQuestions + 1) {
questionNumber = totalQuestions;
}
if (questionNumber < 0) {
questionNumber = 1;
}
//create looping effect
if (questionNumber == totalQuestions + 1) {
questionNumber = 1;
((EditText)v).setText("1");
}
if (questionNumber == 0) {
questionNumber = totalQuestions;
((EditText)v).setText(String.valueOf(totalQuestions));
}
ViewPager pager = (ViewPager) findViewById(R.id.qPager);
pager.setCurrentItem(questionNumber, false);
questionNr.clearFocus();
} else {
questionNr.setText("1");
}
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return false;
}
});
//initialize pager
pager = (ViewPager)findViewById(R.id.qPager);
pagerAdapter = new QuestionPagerAdapter2018ii(getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
pager.setCurrentItem(1, false);
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
#Override
public void onPageSelected(int position) {
Integer currentQuestion = pager.getCurrentItem();
//change spinner
String currentCategory = MyServerData2018ii.getInstance().getQuestionCategory(currentQuestion);
int categoryPosition = MyServerData2018ii.getInstance().getCategoryList().indexOf(currentCategory);
spinCategory.setSelection(categoryPosition);
//change numberPicker
if(currentQuestion <= 0){currentQuestion = totalQuestions;}
if(currentQuestion > totalQuestions){currentQuestion = 1;}
questionNr.setText(currentQuestion.toString());
questionNr.clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(questionNr.getWindowToken(), 0);
}
#Override
public void onPageScrollStateChanged(int state) {
int totalQuestions = MyServerData2018ii.getInstance().getTotalQuestions();
if (state == ViewPager.SCROLL_STATE_IDLE) {
if (pager.getCurrentItem() == totalQuestions + 1) {
pager.setCurrentItem(1, false);
}
if (pager.getCurrentItem() == 0) {
pager.setCurrentItem(totalQuestions, false); // false will prevent sliding animation of view pager
}
}
}
});
}
public void FinishTest(View v){
//check if there are unanswered questions
if(MyServerData2018ii.getInstance().getTestState().equals("inProgress")){
ArrayList<String> UnansweredQuestions = new ArrayList<>();
LinkedHashMap<String,Object> allQuestions = MyServerData2018ii.getInstance().getAllQuestions();
for(Map.Entry category: allQuestions.entrySet()){
Question2018ii[] question2018iis = (Question2018ii[])category.getValue();
for(int i = 0; i < question2018iis.length; i++){
Boolean[] userAnswers = question2018iis[i].getUserAnswers();
if(!Arrays.asList(userAnswers).contains(true)){
String checkedCategory = (String)category.getKey();
Integer questionNumberInList = MyServerData2018ii.getInstance().getQuestionListNumber(checkedCategory,i);
UnansweredQuestions.add(String.valueOf(questionNumberInList));
}
}
}
if(UnansweredQuestions.size() > 0){
dialog = new AlertDialog.Builder(this)
.create();
LayoutInflater infl = LayoutInflater.from(this);
dialog.setView(infl.inflate(R.layout.dialog_message,null));
dialog.show();
TextView message = (TextView)dialog.findViewById(R.id.message);
String unfinished = getResources().getString(R.string.unfinished_text);
String questions = TextUtils.join(",",UnansweredQuestions);
message.setText(unfinished + "\n" + questions + ".");
dialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
showResults();
}
});
}else{showResults();}
}else{
showResults();
}
}
public void showResults(){
int animationDuration;
if(MyServerData2018ii.getInstance().getTestState().equals("finished")){
animationDuration = 10;
}else{
animationDuration = 2000;
}
View mainView = LayoutInflater.from(this).inflate(R.layout.quiz_activity_show_results,null);
LinearLayout mainContainer = (LinearLayout)mainView.findViewById(R.id.mainContainer);
mainView.findViewById(R.id.btnMainMenu).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//finish the test and go to main menu
Intent Main = new Intent(getApplicationContext(),MainActivity.class);
finish();
startActivity(Main);
MyServerData2018ii.getInstance().setTestState("notStarted");
MyServerData2018ii.getInstance().clearAnswers();
Toast.makeText(getBaseContext(),R.string.text_ended,Toast.LENGTH_LONG).show();
}
});
mainView.findViewById(R.id.check_results).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = getIntent();
finish();
startActivity(intent);
}
});
Question2018ii[] currentCategory;
int totalCategoryQuestions;
int correctCategoryQuestions;
int totalCorrectQuestions = 0;
//checking and adding each category
for(String category: allCategories){
View categoryContainer = LayoutInflater.from(this).inflate(R.layout.quiz_activity_category_results,null);
TextView categoryName = (TextView)categoryContainer.findViewById(R.id.categoryName);
//set name
categoryName.setText(category);
currentCategory = MyServerData2018ii.getInstance().getCategory(category);
totalCategoryQuestions = currentCategory.length;
//check answers
correctCategoryQuestions = 0;
for(int i=0; i < currentCategory.length;i++){
Boolean isCorrect = Arrays.equals(currentCategory[i].getAllCorrectAnswers(),currentCategory[i].getUserAnswers());
if(isCorrect){ correctCategoryQuestions++;}
}
totalCorrectQuestions += correctCategoryQuestions;
//set results
String result = String.valueOf(correctCategoryQuestions) + "/" + String.valueOf(totalCategoryQuestions);
final ProgressBar progress = (ProgressBar)categoryContainer.findViewById(R.id.progressBar);
progress.setMax(totalCategoryQuestions*100);
final TextView myResult = (TextView)categoryContainer.findViewById(R.id.categoryResult);
final String myResultText = "/" + String.valueOf(totalCategoryQuestions);
ValueAnimator val = new ValueAnimator();
val.setObjectValues(0, correctCategoryQuestions*100);
val.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
myResult.setText(String.valueOf((Integer)animation.getAnimatedValue()/100) + myResultText);
progress.setProgress( ((Integer) animation.getAnimatedValue()));
}
});
val.setDuration(animationDuration);
val.start();
mainContainer.addView(categoryContainer);
}
//animate results
final TextView tvTotalResult =(TextView)mainView.findViewById(R.id.myTotalAnswers);
final String totalResultS = "/" + String.valueOf(totalQuestions);
ValueAnimator totalResultsAnimator = new ValueAnimator();
totalResultsAnimator.setObjectValues(0, totalCorrectQuestions);
totalResultsAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
tvTotalResult.setText(String.valueOf(animation.getAnimatedValue()) + totalResultS);
}
});
totalResultsAnimator.setDuration(animationDuration);
totalResultsAnimator.start();
MyServerData2018ii.getInstance().setTestState("finished");
setContentView(mainView);
}
}
this is my question yearwise activity(from this I launched the fragment activity)
public class QuestionYearwise extends AppCompatActivity{
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.question_yearwise);
Button btn2018ii = (Button)findViewById(R.id.btn2018ii);
btn2018ii.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent Quiz2018ii = new Intent(getApplicationContext(),QuizActivity2018ii.class);
MyServerData2018ii.getInstance().setTestState("inProgress");
startActivity(Quiz2018ii);
}
});
}
}
Replace the method like this,
mainView.findViewById(R.id.check_results).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
I am trying to change the text and check box response of the clicked list item but I am not able to do so. As I not able to get the click list item.
The fragment is a part of view pager.
Here is my code,
public class ParticipantsFragment extends Fragment {
private ParticipantAdapter mAdapter;
SwipeRefreshLayout refreshLayout;
private String mParticipantId, mEventId, mGender;
ParticipantsAsyncTask task;
public ParticipantsFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mEventId = getArguments().getString(Config.BUNDLE_KEY_EVENT_ID);
mParticipantId = getArguments().getString(Config.BUNDLE_KEY_PARTICIPANT_ID);
mGender = getArguments().getString(Config.BUNDLE_KEY_GENDER);
Log.v("fragh", mEventId + " " + mParticipantId);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.participant_list, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.no_participant);
task = new ParticipantsAsyncTask();
task.execute();
ListView participantListView = (ListView) rootView.findViewById(R.id.participant_list);
refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout_participant_list);
participantListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("Clicked Participant",mAdapter.getItem(position).getParticipantName());
EditText notes = (EditText) rootView.findViewById(R.id.participant_list_item_notes);
String text = notes.getText().toString();
Log.v("Participant Text",text);
CheckBox checkBox = (CheckBox) rootView.findViewById(R.id.participant_list_item_checkbox);
String check;
if(checkBox.isChecked())
{
check = "1";
}
else
{
check = "0";
}
}
});
Button submit = (Button) rootView.findViewById(R.id.submit_participant);
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
mAdapter = new ParticipantAdapter(getContext(), new ArrayList<Participant>());
participantListView.setAdapter(mAdapter);
participantListView.setEmptyView(textView);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
task = new ParticipantsAsyncTask();
task.execute();
refreshLayout.setRefreshing(false);
}
});
return rootView;
}
private class ParticipantsAsyncTask extends AsyncTask<Void, Void, List<Participant>> {
private ProgressDialog progress;
#Override
protected void onPreExecute() {
progress = new ProgressDialog(getContext());
progress.setMessage("Gathering Data...");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.setIndeterminate(true);
progress.setCancelable(false);
progress.show();
}
#Override
protected void onPostExecute(List<Participant> data) {
// Clear the adapter of previous participant data
mAdapter.clear();
// If there is a valid list of {#link Event}s, then add them to the adapter's
// data set. This will trigger the ListView to update.
if (data != null && !data.isEmpty()) {
mAdapter.addAll(data);
}
}
#Override
protected List<Participant> doInBackground(Void... params) {
List<Participant> result;
if (!mGender.isEmpty()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(Config.KEY_EVENT_ID, mEventId);
map.put(Config.KEY_PARTICIPANT_ID, mParticipantId);
map.put(Config.KEY_GENDER, mGender);
result = QueryUtils.extractParticipantData(map, Config.FEVER_GENDER_FILTER_PARTICIPANT_URL);
} else {
HashMap<String, String> map = new HashMap<String, String>();
map.put(Config.KEY_EVENT_ID, mEventId);
map.put(Config.KEY_PARTICIPANT_ID, mParticipantId);
Log.v("law", mEventId + ", " + mParticipantId);
result = QueryUtils.extractParticipantData(map, Config.FEVER_ALL_PARTICIPANT_URL);
}
progress.dismiss();
return result;
}
}
#Override
public void onDestroyView() {
super.onDestroyView();
mAdapter.clear();
}
}
participant_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/no_participant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center_horizontal"
android:text="#string/no_participant_found"
android:textColor="#color/primaryText"
android:textSize="24sp"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout_participant_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="#+id/participant_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/divider"
android:dividerHeight="1dp"
android:descendantFocusability="beforeDescendants"
android:drawSelectorOnTop="true"
android:headerDividersEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout>
<Button
android:id="#+id/submit_participant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20sp"
android:background="#color/colorAccent"/>
</LinearLayout>
participant_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<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="80dp"
android:clickable="true"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:id="#+id/participant_list_item_id"
android:layout_width="0dp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:textSize="20sp"
tools:text="M78" />
<TextView
android:id="#+id/participant_list_item_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_weight="5"
android:textSize="20sp"
android:fontFamily="sans-serif"
tools:text="Billu Barber" />
<EditText
android:id="#+id/participant_list_item_notes"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_weight="6"
android:textSize="12sp"
android:background="#drawable/participant_list_notes"
android:hint="#string/participant_notes"
android:inputType="textMultiLine"
android:scrollbars="none"
android:imeOptions="actionDone"
android:maxLength="50"
android:padding="4dp" />
<CheckBox
android:id="#+id/participant_list_item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" />
</LinearLayout>
My guess is that at the AdapterView.OnItemClickListener you are using rootView to access the cell properties. Like:
EditText notes = (EditText) rootView.findViewById(R.id.participant_list_item_notes);
...
CheckBox checkBox = (CheckBox) rootView.findViewById(R.id.participant_list_item_checkbox);
You should use the parameter View view from onItemClick like that:
EditText notes = (EditText) view.findViewById(R.id.participant_list_item_notes);
...
CheckBox checkBox = (CheckBox) view.findViewById(R.id.participant_list_item_checkbox);
Let me know if it solves your problem.
Edit:
If the problem is having the item clicked, check https://stackoverflow.com/a/20755698/2174489
i have two adapters and a fragment, and i want to display feeds on two views, one bottom and one recycler view. Although the Json was working with a list adapter. its not working with the recycler view.
here is the main fragment
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardExpand;
import it.gmariotti.cardslib.library.internal.CardHeader;
import it.gmariotti.cardslib.library.view.CardViewNative;
import jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout;
public class FeedFragmentAlternative extends Fragment{
private static final String TAG = FeedFragmentAlternative.class.getSimpleName();
private String URL_FEED = "http://api.androidhive.info/feed/feed.json";
private WaveSwipeRefreshLayout mWaveSwipeRefresh;
int duration = 200;
private List<FeedItem> FeedItems;
public static FeedFragmentAlternative newInstance(){
FeedFragmentAlternative feedFragmentAlternative = new FeedFragmentAlternative();
return feedFragmentAlternative;
}
private void refresh(){
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mWaveSwipeRefresh.setRefreshing(false);
}
},3000);
}
private ExpandablePager pager;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.feed_activity_alternate, container, false);
final List<FeedItem> myFeedList = new ArrayList<>();
final FeedExpandableAdapter adapter = new FeedExpandableAdapter(myFeedList);
pager = (ExpandablePager) getActivity().findViewById(R.id.bottom_feed_container);
pager.setAdapter(adapter);
pager.setOnSliderStateChangeListener(new OnSliderStateChangeListener() {
#Override
public void onStateChanged(View page, int index, int state) {
toggleContent(page, state, duration);
}
#Override
public void onPageChanged(View page, int index, int state) {
toggleContent(page, state, 0);
}
});
final RecyclerView mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feeds_list_recycler_view);
mRecyclerView.setHasFixedSize(true);
final FeedGridAdapter a = new FeedGridAdapter(myFeedList);
a.setListener(new OnItemClickedListener() {
#Override
public void onItemClicked(int index) {
pager.setCurrentItem(index, false);
pager.animateToState(ExpandablePager.STATE_EXPANDED);
}
});
mWaveSwipeRefresh = (WaveSwipeRefreshLayout)view.findViewById(R.id.feed_wave_swipe_layout_refresh_alternate);
mWaveSwipeRefresh.setColorSchemeColors(Color.WHITE, Color.GREEN);
mWaveSwipeRefresh.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
pager.setAdapter(adapter);
mRecyclerView.setAdapter(a);
FeedFragmentAlternative.newInstance();
refresh();
}
});
mWaveSwipeRefresh.setWaveColor(Color.parseColor("#80C5EFF7"));
mWaveSwipeRefresh.setMaxDropHeight((int)(mWaveSwipeRefresh.getHeight() * 0.9));
mRecyclerView.setAdapter(a);
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Cache.Entry entry = cache.get(URL_FEED);
if (entry != null){
try {
String data = new String (entry.data, "UTF-8");
try {
parseJsonFeed(new JSONObject(data));
} catch (JSONException e){
e.printStackTrace();
}
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
} else {
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET,
URL_FEED, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response:" + response.toString());
if (response != null){
parseJsonFeed(response);
}
}
},new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "ERROR:" + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jsonReq);
}
return view;
}
private void toggleContent(final View page, final int state, int duration){
final int headerHeight = (int) getResources().getDimension(R.dimen.header_height);
if (page != null){
ValueAnimator animator = state == ExpandablePager.STATE_EXPANDED ? ValueAnimator.ofFloat(1,0): ValueAnimator.ofFloat(0,1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
page.findViewById(R.id.profile_name_header).setTranslationY(25 * (1 - ((Float) animation.getAnimatedValue())));
page.findViewById(R.id.profile_name_header).setTranslationX(-headerHeight * (1 - ((Float)animation.getAnimatedValue())));
page.findViewById(R.id.feed_time_stamp_header).setAlpha(((Float)animation.getAnimatedValue()));
page.findViewById(R.id.profile_pic_header_image).setAlpha(((Float)animation.getAnimatedValue()));
page.findViewById(R.id.feed_like_bottom_sheet).setAlpha(((Float) animation.getAnimatedValue()));
}
});
animator.setDuration((long)(duration * 5));
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
}
private void parseJsonFeed(JSONObject response){
try {
JSONArray feedArray = response.getJSONArray("feed");
for (int i = 0;i < feedArray.length(); i++){
JSONObject feedObj = (JSONObject) feedArray.get(i);
FeedItem item = new FeedItem();
item.setId(feedObj.getInt("id"));
item.setName(feedObj.getString("name"));
String image = feedObj.isNull("image")? null : feedObj
.getString("image");
item.setImge(image);
item.setStatus(feedObj.getString("status"));
item.setProfilePic(feedObj.getString("profilePic"));
item.setTimeStamp(feedObj.getString("timeStamp"));
String feedUrl = feedObj.isNull("url")? null : feedObj
.getString("url");
item.setUrl(feedUrl);
FeedItems.add(item);
}
} catch (JSONException e){
e.printStackTrace();
}
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initCards();
}
private void initCards(){
init_standard_header_with_expandcollapse_button();
}
private void init_standard_header_with_expandcollapse_button(){
Card card = new Card(getActivity());
CardHeader header = new CardHeader(getActivity());
header.setButtonExpandVisible(true);
card.addCardHeader(header);
CardExpand expand = new CardExpand(getActivity());
expand.setTitle("expanded");
CardViewNative cardViewNative = (CardViewNative) getActivity().findViewById(R.id.feed_card_style);
cardViewNative.setCard(card);
}
}
the grid adapter is as follows
public class FeedGridAdapter extends RecyclerView.Adapter<FeedGridAdapter.ViewHolder> {
private OnItemClickedListener listener;
private List<FeedItem> mFeedItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public static class ViewHolder extends RecyclerView.ViewHolder{
public LoginTextView ProfileNameCell;
public LoginTextView FeedTimesStampCell;
public NetworkImageView ProfilepicCell;
public LoginTextView FeedStatusMgsCell;
public FeedImageView FeedImageViewCell;
public ViewGroup container;
public ViewHolder(RelativeLayout v){
super(v);
container = v;
ProfileNameCell = (LoginTextView) v.findViewById(R.id.client_name_alternate_cell);
FeedTimesStampCell = (LoginTextView) v.findViewById(R.id.time_stamp_alternate_cell);
ProfilepicCell = (NetworkImageView) v.findViewById(R.id.profile_pic_alternate_cell);
FeedStatusMgsCell = (LoginTextView) v.findViewById(R.id.txtStatusMgs_alternate);
FeedImageViewCell = (FeedImageView) v.findViewById(R.id.feedImage1_alternate);
}
}
public FeedGridAdapter(List<FeedItem> feedItems){mFeedItems = feedItems;}
#Override
public FeedGridAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RelativeLayout v = (RelativeLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.feed_card_alternate, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.ProfileNameCell.setText(mFeedItems.get(position).getName());
CharSequence timeStampCell = DateUtils.getRelativeTimeSpanString(
Long.parseLong(mFeedItems.get(position).getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
holder.FeedTimesStampCell.setText(timeStampCell);
if (!TextUtils.isEmpty(mFeedItems.get(position).getStatus())){
holder.FeedStatusMgsCell.setText(mFeedItems.get(position).getStatus());
holder.FeedStatusMgsCell.setVisibility(View.VISIBLE);
} else {
holder.FeedStatusMgsCell.setVisibility(View.GONE);
}
holder.ProfilepicCell.setImageUrl(mFeedItems.get(position).getImge(), imageLoader);
if (mFeedItems.get(position).getImge() != null){
holder.FeedImageViewCell.setImageUrl(mFeedItems.get(position).getImge(), imageLoader);
holder.FeedImageViewCell.setVisibility(View.VISIBLE);
holder.FeedImageViewCell
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
holder.FeedImageViewCell.setVisibility(View.GONE);
}
holder.container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listener != null)
listener.onItemClicked(holder.getAdapterPosition());
}
});
}
#Override
public int getItemCount() {
return mFeedItems.size();
}
public void setListener(OnItemClickedListener listener){this.listener = listener;}
}
and the expandable fragment is
public class FeedExpandableAdapter extends ExpandablePagerAdapter<FeedItem> {
public FeedExpandableAdapter(List<FeedItem> items){super(items);}
private LayoutInflater inflater;
private Activity activity;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
#Override
public Object instantiateItem(ViewGroup container, int position) {
final ViewGroup rootView = (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.feed_page_alternative, container, false);
if (inflater == null)
inflater = (LayoutInflater)activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
LoginTextView name = (LoginTextView) rootView.findViewById(R.id.profile_name_header);
LoginTextView timestamp = (LoginTextView) rootView.findViewById(R.id.feed_time_stamp_header);
NetworkImageView profilepic = (NetworkImageView) rootView.findViewById(R.id.profile_pic_header_image);
FeedImageView feedImageView = (FeedImageView) rootView.findViewById(R.id.feed_main_image_bottom_sheet);
LoginTextView statusMgs = (LoginTextView) rootView.findViewById(R.id.body_bottom_panel_feed);
name.setText(items.get(position).getName());
CharSequence timeofStamp = DateUtils.getRelativeTimeSpanString(
Long.parseLong(items.get(position).getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
timestamp.setText(timeofStamp);
if (!TextUtils.isEmpty(items.get(position).getStatus())){
statusMgs.setText(items.get(position).getStatus());
statusMgs.setVisibility(View.VISIBLE);
} else {
statusMgs.setVisibility(View.GONE);
}
profilepic.setImageUrl(items.get(position).getProfilePic(), imageLoader);
if (items.get(position).getImge() != null) {
feedImageView.setImageUrl(items.get(position).getImge(), imageLoader);
feedImageView.setVisibility(View.VISIBLE);
feedImageView
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
feedImageView.setVisibility(View.GONE);
}
return attach(container, rootView, position);
}
}
the error shown is like this -
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.telenav.expandablepager.ExpandablePager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
at com.evolustudios.askin.askin.src.fragments.FeedFragmentAlternative.onCreateView(FeedFragmentAlternative.java:86)
can anyone tell me why its returning null?
its possible duplicate, but i cannot figure out why its returning null
xml - feed_card_alternate
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="350dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<it.gmariotti.cardslib.library.view.CardViewNative
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_card_style"
style="#style/card_external">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame_list_card_item_alternate"
android:background="#drawable/cardpanel"
android:paddingTop="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:id="#+id/feed_top_panel_alternate"
android:paddingBottom="25dp">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/profile_pic_alternate_cell"
android:scaleType="fitCenter"
android:paddingTop="15dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="15dp">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/client_name_alternate_cell"
android:textSize="15dp"
android:textStyle="bold"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/time_stamp_alternate_cell"
android:textColor="#color/timestamp"
android:textSize="13dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/feed_other_content_alternate"
android:layout_below="#+id/feed_top_panel_alternate">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtStatusMgs_alternate"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="13dp" />
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtUrl_alternate"
android:linksClickable="true"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/link" />
<com.evolustudios.askin.askin.src.Utils.FeedImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/feedImage1_alternate"
android:background="#80FFFFFF"
android:scaleType="fitXY"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</it.gmariotti.cardslib.library.view.CardViewNative>
feed_activity_alternate.xml
<FrameLayout 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"
xmlns:tools="http://schemas.android.com/tools">
<jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_wave_swipe_layout_refresh_alternate">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feeds_list_recycler_view"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:scrollbars="vertical"
tools:listitem="#layout/feed_item_list_new">
</android.support.v7.widget.RecyclerView>
<com.telenav.expandablepager.ExpandablePager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bottom_feed_container"
android:layout_gravity="bottom"
app:animation_duration="200"
app:collapsed_height="#dimen/header_height"/>
</jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout>
feed_page_alternative
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#color/pumice">
<include
layout="#layout/feed_header_layout"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250sp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="10dp"
android:id="#+id/feed_bottom_panel_first_container">
<com.evolustudios.askin.askin.src.Utils.FeedImageView
android:layout_width="270sp"
android:layout_height="match_parent"
android:background="#color/edward"
android:id="#+id/feed_main_image_bottom_sheet"
android:scaleType="fitCenter"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scrollbars="none">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_extra_iamge_list_view_bootom_panel">
</ListView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/feed_bottom_panel_second_container"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_very_satisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:src="#drawable/ic_sentiment_satisfied_black_24dp"
android:scaleType="fitCenter"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_neutral_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_dissatisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_very_dissatisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/feed_bottom_panel_third_container"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/very_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/neutral_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/not_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/very_not_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/body_bottom_panel_feed"
android:text="Body"
android:textSize="20dp"/>
</ScrollView>
Change,
pager = (ExpandablePager) getActivity().findViewById(R.id.bottom_feed_container);
to
pager = (ExpandablePager) view.findViewById(R.id.bottom_feed_container);
Also change,
final RecyclerView mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feeds_list_recycler_view);
to
final RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.feeds_list_recycler_view);
I am working on a messaging app which has swipe option to mute or lock conversations, when we press the mute or lock button, small icons are displayed on Recycler view item, but when I try to mute or even lock a certain message it shows the icons on that item but the icons also appears on elements after every 10 counts.
For Example, If I lock the message at position 1, element at position 12 also shows the same icons, if I removed the icon from the first position, icons from the later position is also removed. Any help would be highly appreciated as I am new to android development and still trying to learn.
Picture:
Recycler view items xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="80dp"
android:id="#+id/sample1"
>
<!-- Bottom View Start-->
<LinearLayout
android:id="#+id/leftWrapper"
android:layout_width="120dp"
android:weightSum="1"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:background="#365cf5"
android:layout_width="60dp"
android:weightSum="1"
android:layout_height="match_parent"
android:id="#+id/panelArchieve"
android:orientation="horizontal">
<ImageView
android:id="#+id/archieve"
android:src="#drawable/archieve"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="27dp"/>
</LinearLayout>
<LinearLayout
android:background="#d20909"
android:id="#+id/bottom_wrapper"
android:layout_width="60dp"
android:weightSum="1"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/trash"
android:src="#drawable/trash"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="27dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_wrapper_2"
android:layout_width="120dp"
android:weightSum="1"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:background="#365dea"
android:layout_width="60dp"
android:weightSum="1"
android:layout_height="match_parent"
android:id="#+id/panelLock"
android:orientation="horizontal">
<ImageView
android:id="#+id/lock"
android:src="#drawable/lock"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="27dp"/>
</LinearLayout>
<LinearLayout
android:background="#0e9b04"
android:layout_width="60dp"
android:weightSum="1"
android:id="#+id/panelMute"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/mute"
android:src="#drawable/mute"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="27dp"/>
</LinearLayout>
</LinearLayout>
<!-- Bottom View End-->
<!-- Surface View Start -->
<LinearLayout
android:padding="10dp"
android:background="#303030"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/rv_img_name"
android:src="#drawable/logo"
android:padding="3dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp"
android:layout_marginRight="2dp"
android:id="#+id/rv_title"
android:textColor="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/rv_img_name"
android:layout_toEndOf="#+id/rv_img_name"
android:maxLines="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/rv_content"
android:textColor="#ffffff"
android:layout_below="#+id/rv_title"
android:layout_alignLeft="#+id/rv_title"
android:layout_alignStart="#+id/rv_title"
android:maxLines="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""
android:id="#+id/txtTime"
android:textColor="#ffffff"
android:maxLines="1"
android:layout_alignTop="#+id/rv_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:id="#+id/imgMute"
android:src="#drawable/mute"
android:padding="2dp"
android:layout_marginTop="11dp"
android:layout_toRightOf="#+id/rv_title"
/>
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:id="#+id/imgLock"
android:src="#drawable/lock"
android:padding="2dp"
android:layout_marginTop="11dp"
android:layout_toRightOf="#+id/imgMute" />
</RelativeLayout>
</LinearLayout>
<!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>
RecyclerViewAdapter
#Override
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
//final int position = Texty.position;
final tblMsgs name = mDataset.get(position);
viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
#Override
public void onOpen(SwipeLayout layout) {
}
#Override
public void onClose(SwipeLayout layout) {
viewHolder.btnDel.setTag("trash");
viewHolder.btnDel.setImageResource(R.drawable.trash);
}
});
//Double click
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
#Override
public void onDoubleClick(SwipeLayout layout, boolean surface) {
//Toast.makeText(mContext, "Position: " + position, Toast.LENGTH_SHORT).show();
}
});
//Open conversation.
viewHolder.swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(viewHolder.swipeLayout.getOpenStatus() == SwipeLayout.Status.Open) {
mItemManger.closeAllItems();
viewHolder.btnDel.setTag("trash");
viewHolder.btnDel.setImageResource(R.drawable.trash);
}
else{ //Open conversation
mItemManger.closeAllItems();
Toast.makeText(mContext, " onClick : " + position, Toast.LENGTH_SHORT).show();
}
}
});
//Delete
viewHolder.panelDelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (viewHolder.btnDel.getTag().equals("trash")){
viewHolder.btnDel.setTag("del");
viewHolder.btnDel.setImageResource(R.drawable.delete);
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(view.findViewById(R.id.trash));
}
else if (viewHolder.btnDel.getTag().equals("del")){
viewHolder.btnDel.setTag("trash");
//viewHolder.btnDel.setImageResource(R.drawable.trash);
ds.deleteChat(viewHolder.textViewPos.getTag().toString());
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataset.size());
mItemManger.closeAllItems();
}
}
});
//Mute/Unmute
viewHolder.panelMute.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "Mute unmute pos: " + position, Toast.LENGTH_SHORT).show();
if (viewHolder.btnMute.getTag().equals("bell")){
mItemManger.closeAllItems();
viewHolder.imgMute.setVisibility(View.GONE);
viewHolder.btnMute.setTag("mute");
viewHolder.btnMute.setImageResource(R.drawable.mute);
ds.unMute(name.getrNumber());
}
else{
//Save Sender Settings
ds.open();
if(ds.selectCount_tblSender(name.getrNumber()) == 0){
//Log.i(Log_tag, "Saving settings for " + viewHolder.textViewPos.getTag().toString());
tblSender sndr = new tblSender();
sndr.setNumber(name.getrNumber());
ds.create_tblSender(sndr);
}
mItemManger.closeAllItems();
viewHolder.imgMute.setImageResource(R.drawable.mute);
viewHolder.imgMute.setVisibility(View.VISIBLE);
//YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(view.findViewById(R.id.imgMute));
viewHolder.btnMute.setTag("bell");
//YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(view.findViewById(R.id.mute));
ds.mute(name.getrNumber());
viewHolder.btnMute.setImageResource(R.drawable.bell);
}
//mItemManger.closeAllItems();
//Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewPos.getText().toString() + "!", Toast.LENGTH_SHORT).show();
}
});
//Lock / Unlock
viewHolder.panelLock.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (viewHolder.btnLock.getTag().equals("locked")){
//Save Sender Settings
ds.open();
if(ds.selectCount_tblSender(viewHolder.textViewPos.getTag().toString()) == 0){
//Log.i(Log_tag, "Saving settings for " + viewHolder.textViewPos.getTag().toString());
tblSender sndr = new tblSender();
sndr.setNumber(viewHolder.textViewPos.getTag().toString());
ds.create_tblSender(sndr);
}
mItemManger.closeAllItems();
viewHolder.imgLock.setImageResource(R.drawable.lock);
viewHolder.imgLock.setVisibility(View.VISIBLE);
//YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(view.findViewById(R.id.imgLock));
viewHolder.btnLock.setTag("unlocked");
viewHolder.btnLock.setImageResource(R.drawable.unlock);
//YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(view.findViewById(R.id.lock));
ds.Lock(viewHolder.textViewPos.getTag().toString());
}
else{
mItemManger.closeAllItems();
viewHolder.imgLock.setVisibility(View.GONE);
viewHolder.btnLock.setTag("locked");
viewHolder.btnLock.setImageResource(R.drawable.lock);
ds.unLock(viewHolder.textViewPos.getTag().toString());
}
//mItemManger.closeAllItems();
}
});
//Archieve
viewHolder.panelArchieve.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataset.size());
mItemManger.closeAllItems();
ds.open();
if(ds.selectCount_tblSender(viewHolder.textViewPos.getTag().toString()) == 0){
//Log.i(Log_tag, "Saving settings for " + viewHolder.textViewPos.getTag().toString());
tblSender sndr = new tblSender();
sndr.setNumber(viewHolder.textViewPos.getTag().toString());
ds.create_tblSender(sndr);
}
ds.archieve(viewHolder.textViewPos.getTag().toString());
}
});
viewHolder.textViewPos.setText(name.getSenderName());
viewHolder.textViewPos.setTag(name.getrNumber());
viewHolder.textViewData.setText(name.getMessage().trim());
//Log.i(Log_tag, "Msg: " + name.getMessage().trim());
//viewHolder.txtTime.setText(name.getTime());
//Time Text
try {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
String dateNowStr = formatter.format(date);
Date dateNow = null;
dateNow = formatter.parse(dateNowStr);
String dateSmsStr = name.getTime().substring(0,10);
Date dateSMS = formatter.parse(dateSmsStr);
if (dateSMS.compareTo(dateNow)<0)
{
viewHolder.txtTime.setText(dateSmsStr.substring(0,10)); // + " " + name.getTime().substring(11,name.getTime().length()));
}
else {
viewHolder.txtTime.setText(name.getTime().substring(11,name.getTime().length()));
}
} catch (ParseException e) {
e.printStackTrace();
}
//ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
//int colorRandom = generator.getRandomColor(); // generate random color
//int colorAlpha = generator.getColor(mDataset.get(position).getrName().substring(0,1));//(same key returns the same color)
// declare the builder object once.
TextDrawable.IBuilder builder = TextDrawable.builder()
.beginConfig()
.withBorder(0)
.toUpperCase()
.endConfig()
.round();
int greenColorValue = Color.parseColor("#FF457BDF");
TextDrawable ic1 = builder.build(mDataset.get(position).getrName().substring(0,1), greenColorValue);
viewHolder.imgName.setImageDrawable(ic1);
if(ds.select_tblSender(name.getrNumber()).getIsMute() == 1){ //Mute sign
Log.i(Log_tag, name.getrNumber() + " was muted at position " + position);
viewHolder.btnMute.setTag("bell");
viewHolder.btnMute.setImageResource(R.drawable.bell);
viewHolder.imgMute.setVisibility(View.VISIBLE);
}
if(ds.select_tblSender(name.getrNumber()).getIsProtected() == 1){ //Mute sign
viewHolder.btnLock.setTag("unlocked");
viewHolder.btnLock.setImageResource(R.drawable.unlock);
viewHolder.imgLock.setVisibility(View.VISIBLE);
}
mItemManger.bindView(viewHolder.itemView, position);
}
MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
updateBarHandler = new Handler();
//Fill Inbox
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
// Layout Managers:
recyclerView.setLayoutManager(new LinearLayoutManager(this));
ds = new dataSource(this);
activity = this;
mAdapter = new RecyclerViewAdapter(activity, listInboxAll);
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
recyclerView.setAdapter(mAdapter);
recyclerView.setOnScrollListener(onScrollListener);
//All conversations
GetAllMsgs task = new GetAllMsgs();
task.execute();
}
GetAllMsgs()
private class GetAllMsgs extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
try {
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri uriSMSURI = Uri.parse("content://mms-sms/conversations/");
Cursor cur = contentResolver.query(uriSMSURI, projection, null, null, "date DESC");
int i = 0;
while (cur.moveToNext()) {
String address = cur.getString(cur.getColumnIndex("address"));
final String body = cur.getString(cur.getColumnIndexOrThrow("body"));
final String date = cur.getString(cur.getColumnIndex("date"));
final Long timestamp = Long.parseLong(date);
//Log.i(Log_tag, "Msg: " + body + " from: " + address);
address = address.trim();
if(address.toString().startsWith("92"))
{
address = address.toString().replace("92", "0");
}
else if(address.toString().startsWith("3")){
address = "0" + address;
}
else if(address.toString().startsWith("+92"))
{
address = address.toString().replace("+92", "0");
}
final String nAdd = address;
time = DateFormat.is24HourFormat(activity);
if(time){
dateFormat = new SimpleDateFormat("dd/MM/yyyy k:mm");
}
else{
dateFormat = new SimpleDateFormat("dd/MM/yyyy h:mm a");
}
String usr = getContactName(activity, nAdd);
tblMsgs msg = new tblMsgs();
msg.setMessage(body);
msg.setSenderName(usr); //Fuzool hai for now
msg.setIsSent(1);
msg.setIsReply(0);
msg.setIsUploaded(0);
msg.setIsLocked(0);
msg.setTime(dateFormat.format(timestamp));
msg.setrName(usr); //Name from phone book
msg.setrNumber(nAdd);
msg.setTimeStamp(timestamp);
//listInboxAll.add(msg);
Texty.position = i;
((RecyclerViewAdapter) mAdapter).addnewItem(msg);
i++;
final int j = i;
if(i % 5 == 0){
updateBarHandler.post(new Runnable() {
#Override
public void run () {
((RecyclerViewAdapter) mAdapter).Update(j);
recyclerView.setAdapter(mAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
}
});
}
//listInboxAll.add(msg);
//ds.create(msg);
}
return "done";
}
catch(Exception ex){
Log.e(Log_tag, ex.getMessage());
return "failed";
}
}
#Override
protected void onPostExecute(String result) {
}
}
#Gabe Sechan solved my problem, I had to change the visibility of icons initially.
I am using ViewPager in side activity and add Fragment-State-Pager-Adapter and trying to remove current page position after add the some pages.but every time removed last page position.so please recommend me for use right approach for doing this.Thanks in advance.
This is my activity and adapter code.
public class Main-Activity extends Fragment-Activity implements AddItemFragment.OnFragmentInteractionListener {
PagerAdapter mAdapter;
ViewPager mPager;
Button button ,btn_add;
int pos,TOTAL_PAGES=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
//THIS IS THE MODEL CLASS WHERE I ADD THE PAGES.
MoveItems.items = new ArrayList<>();
MoveItems.items.clear();
Intialize();
}
public void Intialize() {
mPager = (ViewPager)findViewById(R.id.pager);
mAdapter = new PagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mAdapter);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
pos = position + 1;
}
#Override
public void onPageScrollStateChanged(int state) {
//Function.toast(MainActivity.this, "onPageScrollStateChanged");
}
});
Addpage();
button = (Button)findViewById(R.id.delete_current);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mAdapter.deletePage(mPager.getCurrentItem());
Function.toast(MainActivity.this,"'Delete page");
}
});
btn_add=(Button)findViewById(R.id.goto_first);
btn_add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Addpage();
}
});
}
public void Addpage() {
TOTAL_PAGES++;
ItemDescription item = new ItemDescription();
MoveItems.items.add(item);
if (mAdapter != null)
mAdapter.notifyDataSetChanged();
mPager.setCurrentItem((TOTAL_PAGES - 1));
}
#Override
public void onFragmentCreated(ItemDescription itemDescription, int position) {
if (mAdapter != null)
mAdapter.notifyDataSetChanged();
}
public class PagerAdapter extends FragmentStatePagerAdapter
{
public PagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
ItemDescription description = new ItemDescription();
description.setItemNo(position);
description = MoveItems.items.get(position);
return AddItemFragment.newInstance(position, description);
}
#Override
public int getCount() {
return MoveItems.items.size();
}
public void deletePage(int position)
{
MoveItems.items.remove(position);;
notifyDataSetChanged();
}
}
}
This The XML PART
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
<LinearLayout android:orientation="horizontal"
android:gravity="center"
android:measureWithLargestChild="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<!--go to the first page in the view pager-->
<Button android:id="#+id/goto_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First">
</Button>
<!--Delete the current page-->
<Button android:id="#+id/delete_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete">
</Button>
<!--go to the last page in the view pager-->
<Button android:id="#+id/goto_last"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last">
</Button>
</LinearLayout>
</LinearLayout>
THIS THE FRAGMENT CLASS WHERE I INFLATE THE LAYOUT WHICH HAVE CHECK-BOXES AND EDITEXT.
public class AddItemFragment extends Fragment {
// Store instance variables
private int page;
ItemDescription description;
CheckBox furniture, mattress, box, appliance;
EditText other, item_description;
private OnFragmentInteractionListener listener;
LinearLayout line1;
CheckBox checkboxes[];
View v;
// newInstance constructor for creating fragment with arguments
public static AddItemFragment newInstance(int page, ItemDescription item) {
AddItemFragment fragmentFirst = new AddItemFragment();
Bundle args = new Bundle();
args.putInt("pagecount", page);
args.putSerializable("item", item);
fragmentFirst.setArguments(args);
return fragmentFirst;
}
#Override
public void onAttach(Activity activity) {
try {
listener = (OnFragmentInteractionListener) getActivity();
}
catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
}
super.onAttach(activity);
}
/**
* Interface for communicating data
*/
public interface OnFragmentInteractionListener {
public void onFragmentCreated(ItemDescription itemDescription, int position);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_add_item, container, false);
page = getArguments().getInt("pagecount", 0);
description = (ItemDescription) getArguments().getSerializable("item");
One = (CheckBox) v.findViewById(R.id.furniture);
Two = (CheckBox) v.findViewById(R.id.mattress);
Three = (CheckBox) v.findViewById(R.id.box);
Four = (CheckBox) v.findViewById(R.id.appliance);
other = (EditText) v.findViewById(R.id.other);
item_description = (EditText) v.findViewById(R.id.item_description);
checkboxes = new CheckBox[]{One, Two, Three, Four};
return v;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
BitmapsForImage bitmapsForImage = null;
imagePath = "";
if (resultCode == Activity.RESULT_OK) {
if (requestCode == Constants.ImagePick) {
Uri imageUri = getPickImageResultUri(data);
imagePath = getPath(getActivity(), imageUri);
bitmapsForImage = Function.resizeBitmap(imagePath, getActivity());
} else if (Constants.CAMERA_REQUEST_CODE == requestCode) {
bitmapsForImage = Function.resizeBitmap(imagePath, getActivity());
} else if (Constants.GALLERY_IMAGE == requestCode && null != data) {
if (data != null) {
Uri contentURI = data.getData();
String imagePath = Function.getRealPathFromURI(getActivity(), contentURI);
bitmapsForImage = Function.resizeBitmap(imagePath, getActivity());
}
}
if (bitmapsForImage != null && imagePath != null && imagePath.length() > 0) {
MoveItems.itemsBitmapList.set(page, bitmapsForImage.getBitmapToShow());
line1.setVisibility(View.GONE);
description.setItemFilePath(imagePath);
description.setItemFile(new File(imagePath));
MoveItems.items.get(page).setItemFile(new File(imagePath));
MoveItems.items.get(page).setItemFilePath(imagePath);
try {
listener.onFragmentCreated(description, page);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Function.toast(getActivity(), "Some Error Occured");
return;
}
}
}
}
THIS IS THE Fragment_Add_Item WHICH HAVE CHECK BOX AND EDIT TEXT.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:layout_marginTop="20dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:orientation="horizontal">
<CheckBox
android:id="#+id/furniture"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="Furniture"
android:textSize="15sp" />
<CheckBox
android:id="#+id/mattress"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="Mattress"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="5dp"
android:orientation="horizontal">
<CheckBox
android:id="#+id/box"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="Box"
android:textSize="15sp" />
<CheckBox
android:id="#+id/appliance"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="Appliance"
android:textSize="15sp" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/other_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<EditText
android:id="#+id/other"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Other"
android:singleLine="true"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/notes_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/item_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Item Notes"
android:singleLine="true"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Add a Photo"
android:textSize="15sp" />
<TextView android:id="#+id/Des"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This problem occurs when I get any input type inside Fragment_Add_Item layout please help me for find out this problem.This very-very important from me and i am using first time view-pager. In this code item of view-pager deleted but not exact.so i was doing this differnt ways. but not getting right output. thanks in advance.