0

dashboard.xml のタブを作成しています。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">

<TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/WELCOME"
          android:textSize="40dip"
          android:gravity="center"
          android:layout_marginTop="20dip"/>

   <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/emailTextView"/>

<Button android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Logout_Me"
    android:textSize="20dip"
    android:textColor="#21dbd4"
    android:textStyle="bold"
    android:id="@+id/btnLogout"
    android:layout_marginTop="80dip"
    android:background="@null"/>

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>

</RelativeLayout>

しかし、次の 2 つの Java ファイルで常にエラーが発生します: TabsViewPagerFragmentActivity.java

package com.example.loginandregistration;

IMPORTS

public class TabsViewPagerFragmentActivity extends FragmentActivity {

// Declare Variables
ActionBar mActionBar;
ViewPager mPager;
Tab tab;

  @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from dashboard.xml
    setContentView(R.layout.dashboard);

    // Activate Navigation Mode Tabs
    mActionBar = getActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Locate ViewPager in activity_main.xml
    mPager = (ViewPager) findViewById(R.id.pager);

    // Activate Fragment Manager
    FragmentManager fm = getFragmentManager();

    // Capture ViewPager page swipes
    ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            // Find the ViewPager Position
            mActionBar.setSelectedNavigationItem(position);
        }
    };

    mPager.setOnPageChangeListener(ViewPagerListener);
    // Locate the adapter class called ViewPagerAdapter.java
    MyPageAdapter viewpageradapter = new MyPageAdapter(fm);
    // Set the View Pager Adapter into ViewPager
    mPager.setAdapter(viewpageradapter);

    // Capture tab button clicks
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

         @Override
         public void onTabSelected(Tab tab, FragmentTransaction ft) {
             // Pass the position on tab click to ViewPager
             mPager.setCurrentItem(tab.getPosition());
         }

         @Override
         public void onTabUnselected(Tab tab, FragmentTransaction ft) {
             // TODO Auto-generated method stub
         }

         @Override
         public void onTabReselected(Tab tab, FragmentTransaction ft) {
             // TODO Auto-generated method stub
         }
     };



    // Create first Tab
    tab = mActionBar.newTab().setText("Tab1").setTabListener(tabListener);
    mActionBar.addTab(tab);

    // Create second Tab
    tab = mActionBar.newTab().setText("Tab2").setTabListener(tabListener);
    mActionBar.addTab(tab);

    // Create third Tab
    tab = mActionBar.newTab().setText("Tab3").setTabListener(tabListener);
    mActionBar.addTab(tab);

}

}

(46 行目:

MyPageAdapter viewpageradapter = new MyPageAdapter(fm);

エラーで:

The constructor MyPageAdapter(FragmentManager) is undefined TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 46 Java Problem

しかし、コンストラクターを追加するたびに別のエラーが発生し、継続的なエラー ループが発生します)

そして MyPageAdapter:

package com.example.loginandregistration;

import android.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MyPageAdapter extends FragmentPagerAdapter {

// Declare the number of ViewPager pages
final int PAGE_COUNT = 3;

public MyPageAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int arg0) {
    switch (arg0) {

    // Open FragmentTab1.java
    case 0:
        FragmentTab1 fragmenttab1 = new FragmentTab1();
        return fragmenttab1;

    // Open FragmentTab2.java
    case 1:
        FragmentTab2 fragmenttab2 = new FragmentTab2();
        return fragmenttab2;

    // Open FragmentTab3.java
    case 2:
        FragmentTab3 fragmenttab3 = new FragmentTab3();
        return fragmenttab3;
    }
    return null;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return PAGE_COUNT;

}

}

(行のエラー: 18

public Fragment getItem(int arg0) {

23

FragmentTab1 fragmenttab1 = new FragmentTab1();

28

FragmentTab2 fragmenttab2 = new FragmentTab2();

33

 FragmentTab3 fragmenttab3 = new FragmentTab3();

18 行目では、戻り値の型が無効であり、「(Fragment)」に変更するように指示されていますFragmentTabs として (以下に示すように:

        // Open FragmentTab1.java
    case 0:
        CreatePic createpic = new CreatePic();
        return createpic;

) 「CreatePic」が不明であり、戻り値が間違っているというエラーが表示されます (クイックフィックスをクリックすると、エラーのループが作成されます)

どうすればこれを修正できますか?

追加された CREATEPIC.JAVA (上):

package com.example.loginandregistration;


IMPORTS
public class CreatePic extends View {

//drawing path
private Path drawPath;
//drawing and canvas paint
private Paint drawPaint, canvasPaint;
//initial color
private int paintColor = 0xFF660000, paintAlpha = 255;
//canvas
private Canvas drawCanvas;
//canvas bitmap
private Bitmap canvasBitmap;
//brush sizes
private float brushSize, lastBrushSize;
//erase flag
private boolean erase=false;

public CreatePic(Context context, AttributeSet attrs){
    super(context, attrs);
    setupDrawing();
}

//setup drawing
private void setupDrawing(){

    //prepare for drawing and setup paint stroke properties
    brushSize = getResources().getInteger(R.integer.medium_size);
    lastBrushSize = brushSize;
    drawPath = new Path();
    drawPaint = new Paint();
    drawPaint.setColor(paintColor);
    drawPaint.setAntiAlias(true);
    drawPaint.setStrokeWidth(brushSize);
    drawPaint.setStyle(Paint.Style.STROKE);
    drawPaint.setStrokeJoin(Paint.Join.ROUND);
    drawPaint.setStrokeCap(Paint.Cap.ROUND);
    canvasPaint = new Paint(Paint.DITHER_FLAG);
}

//size assigned to view
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    drawCanvas = new Canvas(canvasBitmap);
}

//draw the view - will be called after touch event
@Override
protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);
    canvas.drawPath(drawPath, drawPaint);
}
4

1 に答える 1

1

すべてのインポートが修正されていると思います。CreatePic のフラグメントを作成する必要があります。[ファイル] > [新規] > [クラス] に移動し、CreatePic.java という名前を付けます。

public class CreatePic extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Get the view from createpic.xml
        View view = inflater.inflate(R.layout.createpic , container, false);
        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        setUserVisibleHint(true);
    }

} 
于 2013-09-27T02:20:41.783 に答える