影响列表视图的Android主题

时间:2015-06-22 07:40:17

标签: android parsing android-listview

我正在使用Parse来显示网站上的值,并且它工作得很好。但这只有在我将类扩展为ListActivity

时才有效
public class NewBets extends ListActivity {

整个应用程序正在使用此主题和菜单(我自己的自定义菜单,包含图标和所有内容)

enter image description here

但是当我使用上面的代码显示来自Parse网站的数据时,我无法像上面那样显示菜单

enter image description here

我知道有一些关于Listactivity无法显示菜单的讨论,但没有一个真正解决这个问题。 TKS

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.techiequickie.bharath.betonanything.util.BetsAdapter;

import java.util.List;


public class NewBets extends ListActivity {

    protected List<ParseObject> mBets;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_bets);



        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser !=  null)
        {
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Bets");
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> bets, ParseException e) {
                    if(e == null){

                        mBets = bets;

                    BetsAdapter adapter = new BetsAdapter(getListView().getContext(), mBets);
                        setListAdapter(adapter);


                    }
                }
            });

        }
    }


    @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_standard, 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();

       if (id == R.id.action_settings) {
            return true;}

        return super.onOptionsItemSelected(item); **/
        switch (item.getItemId())
        {


            case R.id.menu_newbet:
                Intent in = new Intent(getApplicationContext(), NewBet.class);
                startActivity(in);
                return true;

            case R.id.menu_earnings:
                Intent nt = new Intent(getApplicationContext(), Earnings.class);
                startActivity(nt);
                return true;

            default:
                return super.onOptionsItemSelected(item);


        }


    }
}

my styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
    </style>
    <style name="AppThemetwo" parent="Theme.AppCompat.Light.DarkActionBar"/>
       Customize your theme here. -->


    <style name="AppThemethree" parent="android:Theme.Holo">

    </style>
</resources>

新的赌注是使用appthemethree

编辑:

在评论中根据建议添加片段,片段显示,但仍然没有显示菜单所需的效果。

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.techiequickie.bharath.betonanything.util.BetsAdapter;

import java.util.List;


public class NewBets extends ActionBarActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_bets);


/**
        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser !=  null)
        {
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Bets");
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> bets, ParseException e) {
                    if(e == null){

                        mBets = bets;

                    BetsAdapter adapter = new BetsAdapter(getListView().getContext(), mBets);
                        setListAdapter(adapter);


                    }
                }
            });

        }**/


        //getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        MyFragment fragment = new MyFragment();
        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
    }


    public static class MyFragment extends ListFragment {
        protected List<ParseObject> mBets;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);





            ParseUser currentUser = ParseUser.getCurrentUser();
            if (currentUser !=  null)
            {
                ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Bets");
                query.findInBackground(new FindCallback<ParseObject>() {
                    @Override
                    public void done(List<ParseObject> bets, ParseException e) {
                        if(e == null){

                            mBets = bets;

                            BetsAdapter adapter = new BetsAdapter(getListView().getContext(), mBets);
                            setListAdapter(adapter);


                        }
                    }
                });

            }
        }
        }

        public void onListItemClick(ListView listView, View view, int position, long id) {

        }



    @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_standard, 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();

       if (id == R.id.action_settings) {
            return true;}

        return super.onOptionsItemSelected(item); **/
        switch (item.getItemId())
        {


            case R.id.menu_newbet:
                Intent in = new Intent(getApplicationContext(), NewBet.class);
                startActivity(in);
                return true;

            case R.id.menu_earnings:
                Intent nt = new Intent(getApplicationContext(), Earnings.class);
                startActivity(nt);
                return true;

            default:
                return super.onOptionsItemSelected(item);


        }


    }
}

enter image description here

如果在投票之前需要适配器代码,请告诉我,tks。

0 个答案:

没有答案