通过使用firebase从listview传递其他活动的多个数据

时间:2018-03-16 23:02:26

标签: android firebase firebase-realtime-database

我创建了简单的状态SHAYARI应用程序  这是我的第一个活动,我在列表视图中从Firebase检索数据然后我采取自定义文本视图,因此在文本视图上单击我打开另一个活动名称是 - > Display_Full_Screen活动。在我的Firebase数据库中,我添加了许多状态并且我成功检索但问题是在其他活动中仅显示一个选定的状态,因此在其他活动中我将两个按钮调用为前进和后退当我单击前进按钮时如何获得下一个状态。?

公共类H_Status_Sub_Activity扩展了AppCompatActivity {

private static ArrayList<String> list;
private static ArrayAdapter<String> adapter;
public static  DatabaseReference databaseReference;
private static  TextView textView;
TextView txt_listview;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_h__status__sub_);
    final Bundle bundle = getIntent().getExtras();
    String main_cat = bundle.getString("name");
    String sub_cat = bundle.getString("name1");
    mlistView = (ListView) findViewById(R.id.h_s_s_listView);
    txt_listview = (TextView) findViewById(R.id.txt_listview);
    databaseReference = FirebaseDatabase.getInstance().getReference("Status").child(main_cat).child(sub_cat);
    list = new ArrayList<>();
    adapter = new ArrayAdapter<String>(this, R.layout.item_listview, R.id.txt_listview, list);
    databaseReference.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            ValueData = String.valueOf((dataSnapshot.getValue()));
            list.add(ValueData);

            mlistView.setAdapter(adapter);
            progressDialog.dismiss();

        }
        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {   adapter.notifyDataSetChanged(); }
        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) { adapter.notifyDataSetChanged(); }
        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) { adapter.notifyDataSetChanged(); }
        @Override
        public void onCancelled(DatabaseError databaseError) { adapter.notifyDataSetChanged(); }
    });

}
public void Display_Txt(View view){
    txt_listview=(TextView)view.findViewById(R.id.txt_listview);
    Bundle bundle = new Bundle();
    bundle.putString("Full Screen Text",txt_listview.getText().toString());
    bundle.putString("list", String.valueOf(list));
    Intent intent = new Intent(H_Status_Sub_Activity.this, Display_Full_Screen_Activity.class);
    intent.putExtras(bundle);
    startActivity(intent);
}

这是我的其他活动我在全尺寸中显示特定文本但在XML文件中有两个按钮调用为前进和倒带当我点击该按钮下一个状态需要出现但我不知道如何那样做

public class Display_Full_Screen_Activity扩展AppCompatActivity {

   private  TextView txt_display_status;

私人按钮

btn_zoomin,btn_zoomout,btn_copy,btn_share,btn_forward,btn_rewind;

    private int x =20;
           private static DatabaseReference databaseReference = H_Status_Main_Activity.databaseReference;
      String Full_Screen_Text;
     String Status_List;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display__full__screen_);

    init();
    Bundle bundle = getIntent().getExtras();
    Full_Screen_Text = bundle.getString("Full Screen Text");
    Status_List = bundle.getString("list");
        txt_display_status.setText(Full_Screen_Text);
}

enter image description here

public void Forward(View view){
    txt_display_status.setText(Status_List + 1);

}
public void Rewind(View view) {



}
public void Zoom_In(View view) {
    txt_display_status.getTextSize();
    txt_display_status.setTextSize((x++));
    txt_display_status.setTextSize(x);
}
public void Zoom_Out(View view) {
    txt_display_status.getTextSize();
    txt_display_status.setTextSize(x--);
    txt_display_status.setTextSize(x);

}
public void Copy(View view) {
    ClipboardManager clipboardManager =(ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("Lable",txt_display_status.getText().toString());
    clipboardManager.setPrimaryClip(clipData);
    Toast.makeText(Display_Full_Screen_Activity.this, "Text Copied" , Toast.LENGTH_SHORT).show();

}
public void Share(View view) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_SUBJECT, "UNTOALD STORY");
    String shareText = txt_display_status.getText().toString();
    // shareText = shareText + "http://www.skynils.com/";
    // if you have live app then you can share link like below
    //shareText = shareText + "https://play.google.com/store/apps/details?id=" + context.getPackageName();
    i.putExtra(Intent.EXTRA_TEXT, shareText);
    startActivity(Intent.createChooser(i, "Share via"));
}
public void whatsapp(View view) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    // i.putExtra(Intent.EXTRA_SUBJECT, "UNTOALD STORY");
    String shareText = txt_display_status.getText().toString();
    // shareText = shareText + "http://www.skynils.com/";
    i.putExtra(Intent.EXTRA_TEXT, shareText);
    i.setPackage("com.whatsapp");
    startActivity(Intent.createChooser(i, "Share via"));

}
public void init(){
    txt_display_status = (TextView) findViewById(R.id.txt_display_status);
    btn_zoomin = (Button) findViewById(R.id.btn_zoomin);
    btn_zoomout = (Button) findViewById(R.id.btn_zoomout);
    btn_copy = (Button) findViewById(R.id.btn_copy);
    btn_copy = (Button) findViewById(R.id.btn_copy);
    btn_share = (Button) findViewById(R.id.btn_share);
    btn_forward = (Button) findViewById(R.id.btn_forward);
    btn_rewind = (Button) findViewById(R.id.btn_rewind);


}

}

0 个答案:

没有答案