0
我試圖在片段上創建一個簡單的反饋表單,但是當我滑動到聯繫人選項卡時,應用程序停止。這裏是我的contactfragment.java代碼:片段上的聯繫表格無法正常工作
package me.hicham.resume;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import me.hicham.resume.R;
public class ContactFragment extends Fragment {
public ContactFragment(){}
Button Send_feedback;
EditText name,email,subject,message;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_contact, container, false);
Send_feedback = (Button) getView().findViewById(R.id.FeedbackButton);
name = (EditText) getView().findViewById(R.id.NameText);
email = (EditText) getView().findViewById(R.id.EmailText);
subject = (EditText) getView().findViewById(R.id.subjecttext);
message = (EditText) getView().findViewById(R.id.messagetext);
Send_feedback.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String b_name = name.getText().toString();
String b_email = email.getText().toString();
String b_subject = subject.getText().toString();
String b_message = message.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_TEXT,b_name);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ b_email});
email.putExtra(Intent.EXTRA_SUBJECT, b_subject);
email.putExtra(Intent.EXTRA_TEXT, b_message);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
});
return rootView;
}
public void onViewCreated (View view, Bundle savedInstanceState){
Typeface opensans = Typeface.createFromAsset(getActivity().getAssets(), "fonts/OpenSans-Light.ttf");
TextView contact1 = (TextView) getView().findViewById(R.id.contact1);
contact1.setTypeface(opensans);
contact1.setText("Let's Talk !");
TextView contacttext = (TextView) getView().findViewById(R.id.contacttext);
contacttext.setTypeface(opensans);
contacttext.setText("\" If you want to discuss a possible project, know more about me, or just have a chitchat :) please get in touch.\"");
EditText nametext = (EditText) getView().findViewById(R.id.NameText);
nametext.setTypeface(opensans);
EditText emailtext = (EditText) getView().findViewById(R.id.EmailText);
emailtext.setTypeface(opensans);
EditText messagetext = (EditText) getView().findViewById(R.id.messagetext);
messagetext.setTypeface(opensans);
EditText subjecttext = (EditText) getView().findViewById(R.id.subjecttext);
subjecttext.setTypeface(opensans);
}
}
這是logcat的說什麼:
01-29 20:27:07.330: E/AndroidRuntime(20311): at me.hicham.resume.ContactFragment.onCreateView(ContactFragment.java:29)
誰能告訴我問題出在哪裏?謝謝。
'Send_feedback =(Button)rootView.findViewById(R.id.FeedbackButton);'相同的其他視圖 – Raghunandan
這解決了我的問題!謝謝@Raghunandan 順便說一句,可以,我的應用程序沒有onCreate()函數? – RidRoid