StartActivity()红色突出显示 [英] StartActivity() red highlighted

查看:157
本文介绍了StartActivity()红色突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想有一个按钮,登录后,开始一个新的活动。 我发现,我是不是能够调用StartActivity()正如我在登录page.Please导以前那样

Basically I want to have a button to start a new activity after login. I found that I was not able to call the StartActivity() as what I did before in the login page.Please guide

这就是我曾经StartActivity(这一点,sth.class)登录页面成功地

This is the login page where I used StartActivity(this,sth.class)sucessfully

public class Login extends Activity
{

/** Called when the activity is first created. */


Button login;
String name="",pass="";
EditText username,password;
TextView tv;
byte[] data;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;
SharedPreferences app_preferences ;
List<NameValuePair> nameValuePairs;
CheckBox check;


public void onCreate(Bundle savedInstanceState)

{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    app_preferences = PreferenceManager.getDefaultSharedPreferences(this);

    username = (EditText) findViewById(R.id.username);
    password = (EditText) findViewById(R.id.password);
    login = (Button) findViewById(R.id.login);
    check = (CheckBox) findViewById(R.id.check);

     String Str_user = app_preferences.getString("username","0" );
    String Str_pass = app_preferences.getString("password", "0");

    String Str_check = app_preferences.getString("checked", "no");
    if(Str_check.equals("yes"))

    {
            username.setText(Str_user);
            password.setText(Str_pass);
            check.setChecked(true);
    }

    login.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)

        {

            name = username.getText().toString();

            pass = password.getText().toString();

            String Str_check2 = app_preferences.getString("checked", "no");

            if(Str_check2.equals("yes"))

            {

                SharedPreferences.Editor editor = app_preferences.edit();

                editor.putString("username", name);

                editor.putString("password", pass);

                 editor.commit();

            }

            if(name.equals("") || pass.equals(""))

            {

                 Toast.makeText(Login.this, "Blank Field..Please Enter", Toast.LENGTH_LONG).show();

            }

            else

            {



            try {

                httpclient = new DefaultHttpClient();

                httppost = new HttpPost("http://fyptest.comyr.com/main.php");

                // Add your data

                nameValuePairs = new ArrayList<NameValuePair>(2);

               nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));

                nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));



                // Execute HTTP Post Request

                response = httpclient.execute(httppost);

                inputStream = response.getEntity().getContent();



                data = new byte[256];



                buffer = new StringBuffer();

                int len = 0;

                while (-1 != (len = inputStream.read(data)) )

                {

                    buffer.append(new String(data, 0, len));

                }


                inputStream.close();

            }



            catch (Exception e)

            {

                Toast.makeText(Login.this, "error"+e.toString(), Toast.LENGTH_LONG).show();

            }

            if(buffer.charAt(0)=='Y')

            {

                Toast.makeText(Login.this, "login successfull", Toast.LENGTH_LONG).show();
                Move_to_next();

            }

            else
        {

                Toast.makeText(Login.this, "Invalid Username or password", Toast.LENGTH_LONG).show();

            }

            }

        }

    });

    check.setOnClickListener(new View.OnClickListener()

    {

        public void onClick(View v)

        {

            // Perform action on clicks, depending on whether it's now checked

            SharedPreferences.Editor editor = app_preferences.edit();

            if (((CheckBox) v).isChecked())

            {



                 editor.putString("checked", "yes");

                 editor.commit();

            }

            else

            {

                 editor.putString("checked", "no");

                 editor.commit();

            }

        }

    });

}



public void Move_to_next()

    {

     //may perform checking based on ID

      startActivity(new Intent(this, MainMenu.class));

    }

不过,这一点,我startActivity被红色下划线

But this, my startActivity is being underlined in red

public class MainMenu extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);

    Button new_folder = (Button)findViewById(R.id.new_folder);
    new_folder.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            // show another class 
            startActivity(new Intent(this,Folder_Details.class));

        }

    });
}

}

这表明构造意图(新View.OnClickListener(){},类)是未定义和删除参数匹配意图()选项

It shows "The constructor Intent(new View.OnClickListener(){}, Class) is undefined" and "Remove arguments to match Intent()" options

我已经包括&LT;活动&GT;&LT; /活动&GT; 的清单。而code上面显示,进口被切断

I have included the <Activity></Activity> in Manifest. And the code showed above, imports are cut off

推荐答案

是的,这是因为,你要使用本与refernce到你的按钮,而不是你的活动。你要取代它这个样子,

Yes this is because, you are trying to use "this" with refernce to your button instead of your activity. You have to replace it like this,

而不是 startActivity(新意图(这一点,Folder_Details.class))的;

做到这一点,

startActivity(new Intent(MainMenu.this, Folder_Details.class));

这篇关于StartActivity()红色突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆