解開對話框後,任何人都可以解決我的ListView不刷新?解除自定義對話框後listview不在刷新片段?
這是我的片段。我設置了適配器和ListView。
public class About extends Fragment {
MyRatingAdapter myRatingAdapter;
ListView listView;
List<ReviewRatingBean> reviewratinglist = new ArrayList<>();
Button buttonsubmit;
EditText editText_name, editText_text;
RatingBar ratingBar;
DataBaseHandler dataBaseHandler;
Button btn_add_reviews;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
//returning our layout file
//change R.layout.yourlayoutfilename for each of your fragments
View view = inflater.inflate(R.layout.about_fragment, container, false);
// ratingbar1=(RatingBar)view.findViewById(R.id.ratingBar1);
// button=(Button)view.findViewById(R.id.button1);
dataBaseHandler = new DataBaseHandler(getActivity());
listView = (ListView) view.findViewById(R.id.list_item);
reviewratinglist = dataBaseHandler.GetAllData();
myRatingAdapter = new MyRatingAdapter(getActivity(), reviewratinglist);
listView.setAdapter(myRatingAdapter);
btn_add_reviews = (Button)view.findViewById(R.id.btn_addreviews);
btn_add_reviews.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public void onClick(View view) {
LayoutInflater inflater = getLayoutInflater(savedInstanceState);
View dialoglayout = inflater.inflate(R.layout.activity_review_rating, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(dialoglayout);
final AlertDialog alertDialog = builder.create();
buttonsubmit = (Button)dialoglayout.findViewById(R.id.btn_submit);
editText_name = (EditText)dialoglayout.findViewById(R.id.et_name);
editText_text = (EditText)dialoglayout.findViewById(R.id.et_text);
ratingBar = (RatingBar)dialoglayout.findViewById(R.id.rating_bar);
ratingBar.setIsIndicator(false);
buttonsubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ReviewRatingBean reviewRatingBean = new ReviewRatingBean();
String name = editText_name.getText().toString();
float rate = ratingBar.getRating();
String text = editText_text.getText().toString();
reviewRatingBean.setName(name);
reviewRatingBean.setRating(rate);
reviewRatingBean.setTextreview(text);
dataBaseHandler.addData(reviewRatingBean);
Toast.makeText(getContext(), "Thanks For Your FeedBack", Toast.LENGTH_SHORT).show();
myRatingAdapter.notifyDataSetChanged(); here i have try to notify the base adpater to refreshing a list view
listView.setAdapter(myRatingAdapter);
alertDialog.dismiss();
}
});
alertDialog.show();
}
});
return view;
}
}
你希望人們把時間花在你的問題,所以請讓時間花在你的你的問題。請讓我們看看[mcve]和[問] – xiawi