导航抽屉 - >活动段片段

时间:2017-05-17 22:03:17

标签: java android eclipse import

我遇到了麻烦,这段代码无效 我认为我的错误是在类中,它具有类check1a4中的和的函数。它应该是一个片段'?

我尝试在一些教程中搜索,但我找不到解决方案。

MainActivity

<div class="image-container"
    style="background-image: url(https://lorempixel.com/400/200/cats/1/)"
></div>

<br>

<div class="image-container"
    style="background-image: url(https://lorempixel.com/200/400/cats/1/)"
></div>

}

** java **

package com.journaldev.navigationdrawer;  
import android.support.v4.app.Fragment;  
import android.support.v4.app.FragmentManager;  
import android.support.v4.widget.DrawerLayout;  
import android.support.v7.app.AppCompatActivity;  
import android.os.Bundle;  
import android.support.v7.widget.Toolbar;  
import android.util.Log;  
import android.view.MenuItem;  
import android.view.View;  
import android.widget.AdapterView;  
import android.widget.ListView;  
public class MainActivity extends AppCompatActivity {  
private String[] mNavigationDrawerItemTitles;  
private DrawerLayout mDrawerLayout;  
private ListView mDrawerList;  
Toolbar toolbar;  
private CharSequence mDrawerTitle;  
private CharSequence mTitle;  
android.support.v7.app.ActionBarDrawerToggle mDrawerToggle;  

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mTitle = mDrawerTitle = getTitle();
    mNavigationDrawerItemTitles= getResources().getStringArray(R.array.navigation_drawer_items_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    setupToolbar();

    DataModel[] drawerItem = new DataModel[3];

    drawerItem[0] = new DataModel(R.drawable.connect, "Check List (1 a 4)");
    drawerItem[1] = new DataModel(R.drawable.fixtures, "Check List (1 a 19)");
    drawerItem[2] = new DataModel(R.drawable.table, "Sobre a sove");

    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(true);

    DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.list_view_item_row, drawerItem);
    mDrawerList.setAdapter(adapter);
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    setupDrawerToggle();


}

private class DrawerItemClickListener implements ListView.OnItemClickListener {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectItem(position);
    }

}

private void selectItem(int position) {

    Fragment fragment = null;

    switch (position) {
        case 0:
            fragment = new ConnectFragment();
            break;
        case 1:
            fragment = new FixturesFragment();
            break;
        case 2:
            fragment = new TableFragment();
            break;


        default:
            break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(mNavigationDrawerItemTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);

    } else {
        Log.e("MainActivity", "Error in creating fragment");
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getSupportActionBar().setTitle(mTitle);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    mDrawerToggle.syncState();
}

void setupToolbar(){
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
}

void setupDrawerToggle(){
    mDrawerToggle = new android.support.v7.app.ActionBarDrawerToggle(this,mDrawerLayout,toolbar,R.string.app_name, R.string.app_name);
    //This is necessary to change the icon of the Drawer Toggle upon state change.
    mDrawerToggle.syncState();
}

R.layout.check1a

package com.journaldev.navigationdrawer;  
import android.app.Activity;  
import android.os.Bundle;  
import android.support.v7.app.AppCompatActivity;  
import android.view.View;  
import android.widget.Button;  
import android.widget.CheckBox;  
import android.widget.EditText;  
import android.app.Activity;  
import android.os.Bundle;  
import android.app.AlertDialog;  
import android.widget.*;  
import android.view.*;  

public class check1a4 extends Activity {  
/** Called when the activity is first created. */  
CheckBox a,s,d,f,g,h,j,k,q,w,e,rr,t,y,u,i,z,x,c,v,b,n,m, aa,ss,dd,ff;  
EditText resultado;  
EditText hh,jj,kk,fr,qq,ww,ee;  

@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check1a4);

a = (CheckBox) findViewById(R.id.a);
s = (CheckBox) findViewById(R.id.s);
d = (CheckBox) findViewById(R.id.d);
f = (CheckBox) findViewById(R.id.f);
g = (CheckBox) findViewById(R.id.g);
h = (CheckBox) findViewById(R.id.h);
j = (CheckBox) findViewById(R.id.j);
k = (CheckBox) findViewById(R.id.k);
q = (CheckBox) findViewById(R.id.q);
w = (CheckBox) findViewById(R.id.w);
e = (CheckBox) findViewById(R.id.e);
t = (CheckBox) findViewById(R.id.t);
y = (CheckBox) findViewById(R.id.y);
u = (CheckBox) findViewById(R.id.u);
i = (CheckBox) findViewById(R.id.i);
z = (CheckBox) findViewById(R.id.z);
x = (CheckBox) findViewById(R.id.x);
c = (CheckBox) findViewById(R.id.c);
v = (CheckBox) findViewById(R.id.v);
b = (CheckBox) findViewById(R.id.b);
n = (CheckBox) findViewById(R.id.n);
m = (CheckBox) findViewById(R.id.m);
rr = (CheckBox) findViewById(R.id.rr);
aa = (CheckBox) findViewById(R.id.aa);
ss = (CheckBox) findViewById(R.id.ss);
dd = (CheckBox) findViewById(R.id.dd);
ff = (CheckBox) findViewById(R.id.ff);

resultado = (EditText) findViewById(R.id.total);


hh = (EditText) findViewById(R.id.hh);
jj = (EditText) findViewById(R.id.jj);
kk = (EditText) findViewById(R.id.kk);
fr = (EditText) findViewById(R.id.fr);
qq = (EditText) findViewById(R.id.qq);
ww = (EditText) findViewById(R.id.ww);
ee = (EditText) findViewById(R.id.ee);



Button bttotal = (Button) findViewById(R.id.btsomar);
bttotal.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {

double total = 0;

if (a.isChecked()) {
total += 10.0;
            }
 if (s.isChecked()) {
                total += 5.00;
            }
            if (d.isChecked()) {
                total += 5.00;
            }
            if (f.isChecked()) {
                total += 4.00;
            }

            if (g.isChecked()) {
                total += 1.00;
            }

            if (h.isChecked()) {
                total += 1.00;
            }

            if (j.isChecked()) {
                total += 1.00;
            }

            if (k.isChecked()) {
                total += 2.00;
            }

            if (q.isChecked()) {
                total += 1.00;
            }

            if (w.isChecked()) {
                total += 2.00;
            }
            if (e.isChecked()) {
                total += 2.00;
            }
            if (rr.isChecked()) {
                total += 1.00;
            }
            if (t.isChecked()) {
                total += 3.50;
            }
            if (y.isChecked()) {
                total += 3.50;
            }
            if (u.isChecked()) {
                total += 1.00;
            }
            if (z.isChecked()) {
                total += 4.50;
            }
            if (x.isChecked()) {
                total += 6.00;
            }
            if (c.isChecked()) {
                total += 4.50;
            }
            if (v.isChecked()) {
                total += 1.00;
            }
            if (b.isChecked()) {
                total += 1.00;
            }

            if (z.isChecked()) {
                total += 4.50;
            }

            if (n.isChecked()) {
                total += 6.00;
            }

            if (m.isChecked()) {
                total += 4.00;
            }
            if (aa.isChecked()) {
                total += 1.50;
            }
            if (ss.isChecked()) {
                total += 2.00;
            }
            if (dd.isChecked()) {
                total += 2.50;
            }
            if (ff.isChecked()) {
                total += 2.00;
            }

            double num1  =    Double.parseDouble(hh.getText().toString());
            double num2  =   Double.parseDouble(jj.getText().toString());
            double num3   =   Double.parseDouble(kk.getText().toString());
            double num4  =     Double.parseDouble(qq.getText().toString());
            double num5  =   Double.parseDouble(ww.getText().toString());
            double num6  =    Double.parseDouble(ee.getText().toString());
            double num7  =    Double.parseDouble(fr.getText().toString());



            ////

            resultado.setText(String.valueOf(num1+num2+num3+num4+num5+num6+num7+total));
        }
    });
}}

0 个答案:

没有答案
相关问题