Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

android - How to use Firebase List adapter

I'm trying to follow with this tutorial:

https://www.youtube.com/watch?v=2J6spwAVP0M

but implementing it on my complex app just didn't work so I tried from scratch..

I created this simple MainActivity:

public class MainActivity extends AppCompatActivity{

    Firebase mRef;
    com.firebase.ui.FirebaseListAdapter<String> myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mRef = new Firebase("https://<myURL>..");

        myAdapter = new FirebaseListAdapter<String>(this,String.class,android.R.layout.simple_list_item_1,mRef) {
            @Override
            protected void populateView(View view, String s, int i) {
                TextView text = (TextView)view.findViewById(android.R.id.text1);
                text.setText(s);

            }
        };
        Button addBtn = (Button) findViewById(R.id.add_button);
        addBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mRef.push().setValue("test123");
            }
        });
    }
}

Now I have a few questions:

1) what triggers the populateView? I just couldn't make it run

2) what exactly should the android.R.layout.simple_list_item_1 be replaced with? I tried creating my own listview and replace the above with my R.id.listView but nothing happens.. I can't figure out how this magic works..

3) even this simple app didn't work.. the button does add the "test123" to the right place on the server but I see nothing on my app.. whats wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...