还有其他方法可以为我的轮播调用意图活动吗?这是我的错误:
错误:(105,39)错误:找不到符号方法getArguments()
我添加了:
final int pos = this.getArguments()。getInt(“ pos”);
但它显示了我
找不到符号方法getArguments()的错误
这是我的代码:
package com.android.msahakyan.expandablenavigationdrawer.fragment;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.msahakyan.expandablenavigationdrawer.R;
import com.android.msahakyan.expandablenavigationdrawer.Registration;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import in.goodiebag.carouselpicker.CarouselPicker;
import technolifestyle.com.imageslider.FlipperLayout;
import technolifestyle.com.imageslider.FlipperView;
public class FragmentAction extends Fragment {
CarouselPicker carouselPicker1;
ViewPager viewPager;
private static final String KEY_MOVIE_TITLE = "key_title";
public FragmentAction() {
// Required empty public constructor
}
public static FragmentAction newInstance(String movieTitle) {
FragmentAction fragmentAction = new FragmentAction();
Bundle args = new Bundle();
args.putString(KEY_MOVIE_TITLE, movieTitle);
fragmentAction.setArguments(args);
return fragmentAction;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragment_action,container,false);
TextView txt = (TextView)v.findViewById( R.id.textView12 );
txt.setText("\u25BA Creative & Dedicated Team");
TextView txt1 = (TextView)v.findViewById( R.id.textView13 );
txt1.setText("\u25BA Affordable Cost");
TextView txt2 = (TextView)v.findViewById( R.id.textView14 );
txt2.setText("\u25BA Maintain Long Relationship");
TextView txt3 = (TextView)v.findViewById( R.id.textView15 );
txt3.setText("\u25BA Timely Deliverly ");
viewPager = (ViewPager)v.findViewById( R.id.viewpager );
ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter( this.getContext() );
viewPager.setAdapter( viewPagerAdapter );
Timer timer = new Timer( );
timer.scheduleAtFixedRate( new Mytime(),2000,4000 );
CarouselPicker carouselPicker1 = (CarouselPicker)v.findViewById( R.id.carouselPicker1 );
List<CarouselPicker.PickerItem> itemsImages = new ArrayList<>();
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.website_design));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.digital_marketing));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.domain_registration));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.graphic));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.mob));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.server));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.software_development));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.ontent));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.ssl));
carouselPicker1.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
final int pos = this.getArguments().getInt("pos");
switch (pos)
{
case 0: Intent newActivity0 = new Intent(getActivity(), website_designing.class);
startActivity(newActivity0);
break;
case 1: Intent newActivity1 = new Intent(getActivity(), digital_marketing.class);
startActivity(newActivity1);
break;
case 2: Intent newActivity2 = new Intent(getActivity(), DomainRegistration.class);
startActivity(newActivity2);
break;
case 3: Intent newActivity3 = new Intent(getActivity(), GraphicDesign.class);
startActivity(newActivity3);
break;
case 4: Intent newActivity4 = new Intent(getActivity(), MobileApps.class);
startActivity(newActivity4);
break;
case 5: Intent newActivity5 = new Intent(getActivity(), ServerHosting.class);
startActivity(newActivity5);
break;
case 6: Intent newActivity6 = new Intent(getActivity(), SoftwareDevelopment.class);
startActivity(newActivity6);
break;
case 7: Intent newActivity7 = new Intent(getActivity(), SoftwareDevelopment.class);
startActivity(newActivity7);
break;
case 8: Intent newActivity8 = new Intent(getActivity(), SSL.class);
startActivity(newActivity8);
break;
}
}
} );
// CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this,itemsImages,0);
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this.getContext(),itemsImages,0);
carouselPicker1.setAdapter(imageAdapter);
FloatingActionButton floatingActionButton = (FloatingActionButton)v.findViewById( R.id.floatingActionButton );
floatingActionButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity( new Intent( getActivity(),Registration.class ) );
}
} );
// carouselPicker1.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
// @Override
// public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
// }
//
//
//
// @Override
// public void onPageSelected(int position) {
// if(position == 0){
// startActivity(new Intent(getActivity(), website_designing.class));
// }
// else if(position == 1){
// startActivity(new Intent(getActivity(), digital_marketing.class));
// }
// else if(position == 2){
// startActivity(new Intent(getActivity(), DomainRegistration.class));
// }
// else if(position == 3){
// startActivity(new Intent(getActivity(), GraphicDesign.class));
// }
// else if(position == 4){
// startActivity(new Intent(getActivity(), MobileApps.class));
// }
// else if(position == 5){
// startActivity(new Intent(getActivity(), ServerHosting.class));
// }
// else if(position == 6){
// startActivity(new Intent(getActivity(), SoftwareDevelopment.class));
// }
// else if(position == 7){
// startActivity(new Intent(getActivity(), ContentWriting.class));
// }
// else if(position == 8){
// startActivity(new Intent(getActivity(), SSL.class));
// }
// }
//
// @Override
// public void onPageScrollStateChanged(int state) {
//
// }
// });
// ImageButton imageButton =(ImageButton)v.findViewById(R.id.movie_icon);
// imageButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// startActivity( new Intent( getActivity(), Registration.class ) );
// }
// });
return v;
}
public class Mytime extends TimerTask{
@Override
public void run() {
getActivity().runOnUiThread( new Runnable() {
@Override
public void run() {
if(viewPager.getCurrentItem() == 0) {
viewPager.setCurrentItem( 1 );
}
else if (viewPager.getCurrentItem()== 1){
viewPager.setCurrentItem( 2 );
}
else if (viewPager.getCurrentItem()== 2){
viewPager.setCurrentItem( 3 );
}
else if (viewPager.getCurrentItem()== 3){
viewPager.setCurrentItem( 4 );
}
else {
viewPager.setCurrentItem(0);
}
}
} );
}
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Drawable movieIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.webdesign, getContext().getTheme());
String movieTitle = getArguments().getString(KEY_MOVIE_TITLE);
}
}
答案 0 :(得分:0)
您应按照以下说明将this.getArguments()
从onClick
中移出
final int pos = this.getArguments().getInt("pos");
carouselPicker1.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (pos)
{
case 0: Intent newActivity0 = new Intent(getActivity(), website_designing.class);
startActivity(newActivity0);
break;
case 1: Intent newActivity1 = new Intent(getActivity(), digital_marketing.class);
startActivity(newActivity1);
break;
case 2: Intent newActivity2 = new Intent(getActivity(), DomainRegistration.class);
startActivity(newActivity2);
break;
case 3: Intent newActivity3 = new Intent(getActivity(), GraphicDesign.class);
startActivity(newActivity3);
break;
case 4: Intent newActivity4 = new Intent(getActivity(), MobileApps.class);
startActivity(newActivity4);
break;
case 5: Intent newActivity5 = new Intent(getActivity(), ServerHosting.class);
startActivity(newActivity5);
break;
case 6: Intent newActivity6 = new Intent(getActivity(), SoftwareDevelopment.class);
startActivity(newActivity6);
break;
case 7: Intent newActivity7 = new Intent(getActivity(), SoftwareDevelopment.class);
startActivity(newActivity7);
break;
case 8: Intent newActivity8 = new Intent(getActivity(), SSL.class);
startActivity(newActivity8);
break;
}
}
} );
因为this
不是您片段的实例。
答案 1 :(得分:0)
使用getArguments()而不使用它。
final int pos = getArguments().getInt("pos");