I use Android Studio, it's my very first time developing for android
and also java language!
So, upon building my project and running it on my own phone, it crashes when
I enter a second activity.
This is the xml of the activity I try to open.:(activity_infomenu.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fullscreen_content"
android:background="#ff282bff"
android:fitsSystemWindows="true"
android:keepScreenOn="true"
android:gravity="center"
tools:context="com.luiscesjr.aquariodebolso.aquariodebolso.infomenu">
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button7"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/calendar128"
/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button8"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/button11"
android:layout_alignStart="#+id/button11"
android:src="#drawable/fish128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button9"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/button12"
android:layout_alignStart="#+id/button12"
android:src="#drawable/clown_fish128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button10"
android:layout_marginTop="102dp"
android:layout_below="#+id/button7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/ruler128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button11"
android:layout_alignTop="#+id/button10"
android:layout_centerHorizontal="true"
android:src="#drawable/ruler128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button12"
android:layout_alignTop="#+id/button11"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/ruler128"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Calendário"
android:id="#+id/textView"
android:layout_below="#+id/button7"
android:layout_alignRight="#+id/textView4"
android:layout_alignEnd="#+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Aqua Doce"
android:id="#+id/textView2"
android:layout_below="#+id/button8"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Aqua Marinho"
android:id="#+id/textView3"
android:layout_below="#+id/button9"
android:layout_alignLeft="#+id/button9"
android:layout_alignStart="#+id/button9" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Ferramentas"
android:id="#+id/textView4"
android:layout_below="#+id/button10"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView5"
android:layout_below="#+id/button11"
android:layout_alignRight="#+id/button11"
android:layout_alignEnd="#+id/button11" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView6"
android:layout_below="#+id/button12"
android:layout_alignLeft="#+id/button12"
android:layout_alignStart="#+id/button12" />
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</RelativeLayout>
The Code.: (infomenu.java)
(This is the auto generated activity with fullscreen form the Android Studio.)
package com.luiscesjr.aquariodebolso.aquariodebolso;
import com.luiscesjr.aquariodebolso.aquariodebolso.util.SystemUiHider;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.graphics.drawable.AnimationDrawable;
public class infomenu extends Activity {
private static final boolean AUTO_HIDE = true;
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
private static final boolean TOGGLE_ON_CLICK = true;
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
private SystemUiHider mSystemUiHider;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_infomenu);
setupActionBar();
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
// Cached values.
int mControlsHeight;
int mShortAnimTime;
#Override
#TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
if (mControlsHeight == ) {
// LINE 83 HERE mControlsHeight = controlsView.getHeight();
}
if (mShortAnimTime == 0) {
mShortAnimTime = getResources().getInteger(
android.R.integer.config_shortAnimTime);
}
controlsView.animate()
.translationY(visible ? 0 : mControlsHeight)
.setDuration(mShortAnimTime);
} else {
controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
if (visible) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
contentView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (TOGGLE_ON_CLICK) {
mSystemUiHider.toggle();
} else {
mSystemUiHider.show();
}
}
});
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
delayedHide(100);
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
#Override
public void run() {
mSystemUiHider.hide();
}
};
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}
And here is the Error.:
05-20 22:48:24.737 18794-18794/com.luiscesjr.aquariodebolso.aquariodebolso E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.luiscesjr.aquariodebolso.aquariodebolso.infomenu$1.onVisibilityChange(infomenu.java:83)
at com.luiscesjr.aquariodebolso.aquariodebolso.util.SystemUiHiderHoneycomb$1.onSystemUiVisibilityChange(SystemUiHiderHoneycomb.java:112)
at android.view.View.dispatchSystemUiVisibilityChanged(View.java:15933)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1412)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1418)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1418)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1418)
at android.view.ViewRootImpl.handleDispatchSystemUiVisibilityChanged(ViewRootImpl.java:3777)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2966)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
05-20 22:48:26.417 18794-18794/com.luiscesjr.aquariodebolso.aquariodebolso I/Process﹕ Sending signal. PID: 18794 SIG: 9
What am I missing here?
Oh and please, don't mind the idiotic name of the app.
Edit.: Won't have the error anymore since I added this.:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff282bff"
android:fitsSystemWindows="true"
android:keepScreenOn="true"
android:gravity="center"
tools:context="com.luiscesjr.aquariodebolso.aquariodebolso.infomenu"
android:id="#+id/fullscreen_content_controls">
<View //Without this it will still crash, but it also bugs the activity
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fullscreen_content">
</View>
But now the code won't work properly.
You are setting controlsView value to this
final View controlsView = findViewById(R.id.fullscreen_content_controls);
but fullscreen_content_controls is not present in your layout
Add your Required view to your layout because your given layout does not contains any thing like fullscreen_content_controls, So it is throwing NPE
Related
1.Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
2.First I added my two activities then I got this error
Below is XML code:-
Exact what line i got this error please give the solution with code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<TextView
android:id="#+id/textview"
android:layout_width="346dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Text to Speech"
android:textColor="#F32269"
android:textSize="28dp"
android:textStyle="bold" />
<SeekBar
android:id="#+id/seek_bar_speed"
android:layout_width="389dp"
android:layout_height="28dp"
android:layout_below="#id/textview"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:layout_marginEnd="4dp"
android:progress="50" />
<TextView
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_alignBottom="#id/textview"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="1dp"
android:layout_marginTop="41dp"
android:layout_marginBottom="-29dp"
android:gravity="center"
android:text="Speed"
android:textColor="#color/black"
android:textSize="20dp" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="363dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:layout_marginStart="0dp"
android:layout_marginTop="100dp"
android:layout_marginEnd="2dp">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" Enter Text "
android:textColor="#000000"
android:textColorHint="#51FA2B"
android:textSize="20dp"
tools:layout_conversion_absoluteHeight="45dp"
tools:layout_conversion_absoluteWidth="89dp"
tools:layout_editor_absoluteX="12dp"
tools:layout_editor_absoluteY="179dp" />
</ScrollView>
<Button
android:id="#+id/button"
android:layout_width="418dp"
android:layout_height="71dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginTop="74dp"
android:layout_marginEnd="-7dp"
android:layout_marginBottom="134dp"
android:text="Text to speech"
android:textSize="18dp"
android:textStyle="bold"/>
</RelativeLayout>
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.SeekBar;
public class MainActivity2 extends AppCompatActivity {
TextView textView;
private SeekBar mseekbar;
TextToSpeech t1;
EditText ed1;
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.editText);
b1 = findViewById(R.id.button);
textView = findViewById(R.id.text);
mseekbar = findViewById(R.id.seek_bar_speed);
t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.US);
}
}
});
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String toSpeak = ed1.getText().toString();
float speed = (float) mseekbar.getProgress() / 50;
t1.setSpeechRate(speed);
Toast.makeText(MainActivity2.this.getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
public void onPause() {
if (t1 != null) {
t1.stop();
}
super.onPause();
}
}```
I am trying to do app, where you have 3 SeekBars and under them, there are 3 TextFields, which are showing shade of each color, and under those is TextField, which is changing color when you are moving SeekBar. When I try to lunch it on mobile, it say's that the app "Keeps stopping". Thanks for help.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity"
android:orientation="vertical">
<SeekBar
android:id="#+id/SB1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="183dp"
android:max="255"></SeekBar>
<SeekBar
android:id="#+id/SB2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="114dp"
android:max="255"></SeekBar>
<SeekBar
android:id="#+id/SB3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
android:max="255"></SeekBar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="279dp">
<TextView
android:id="#+id/TVr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_gravity="left"
android:text="R = 0"
android:textSize="30sp" />
<TextView
android:id="#+id/TVg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_gravity="center"
android:text="G = 0"
android:textSize="30sp" />
<TextView
android:id="#+id/TVb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="false"
android:layout_gravity="right"
android:text="B = 0"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="#+id/vysledek"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="67dp" />
</RelativeLayout>
package com.example.posuvnik;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
SeekBar SB1;
SeekBar SB2;
SeekBar SB3;
TextView vysledek;
TextView TVr, TVb, TVg;
private int seekR, seekG, seekB;
public class MySeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId()) {
case R.id.SB1:
seekR = progress;
TVr.setText(seekR);
break;
case R.id.SB2:
seekG = progress;
TVg.setText(seekG);
break;
case R.id.SB3:
seekB = progress;
TVb.setText(seekB);
break;
}
int barva = Color.rgb(seekR,seekG,seekB);
vysledek.setBackgroundColor(barva);
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_color_changer);
SeekBar sbR = (SeekBar) findViewById(R.id.SB1);
SeekBar sbG = (SeekBar) findViewById(R.id.SB2);
SeekBar sbB = (SeekBar) findViewById(R.id.SB3);
MySeekBarChangeListener msbclR = new MySeekBarChangeListener();
MySeekBarChangeListener msbclG = new MySeekBarChangeListener();
MySeekBarChangeListener msbclB = new MySeekBarChangeListener();
sbR.setOnSeekBarChangeListener(msbclR);
sbG.setOnSeekBarChangeListener(msbclG);
sbB.setOnSeekBarChangeListener(msbclB);
}
}
You didn't initialize text views...
TVr = findViewById(R.id.TVr); - do it for all 3 TextViews TVr, TVg, TVb;
Also:
You have to initialize vysledek.
You have to cast progress (seekR, seekG, seekB) to String in onProgressChanged() method - TVr.setText(String.valueOf(seekR));
Your layout is also very poor. You haven't mentioned the orientation android:orientation="horizontal" and the positioning for the LinearLayout as well.
I am developing an application with accessing gesture of android. I am not able to swipe over the layout where some texts are visible,but able to swipe in blank spaces of activity.
my java code
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.tomcast.libin.anxiety.R;
import com.tomcast.libin.anxiety.models.Questions;
import com.tomcast.libin.anxiety.utils.OnSwipeTouchListener;
import com.tomcast.libin.anxiety.utils.SlideAnimationUtil;
import java.util.ArrayList;
public class DFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private ArrayList<Questions> questionlist = new ArrayList<Questions>();
private static int START_POSITION=0;
private static int FINAL_POSITION=6;
private static int CURRENT_POSTION =0;
ConstraintLayout llQuestion;
TextView question;
ImageView iconA;
ImageView iconB;
ImageView iconC ;
ImageView iconD;
float x1,y1,x2,y2,t1,t2;
`enter code here`int CLICK_DURATION = 10;
private OnFragmentInteractionListener mListener;
public DFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static Fragment newInstance(String param1, String param2) {
Fragment fragment = new Fragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.sliding_question_layout, container, false);
init( view);
return view ;
}
void init(final View view){
llQuestion=(ConstraintLayout) view.findViewById(R.id.constraintLayout);
iconA= view.findViewById(R.id.ic_option_a);
iconB= view.findViewById(R.id.ic_option_b);
iconC= view.findViewById(R.id.ic_option_c);
iconD= view.findViewById(R.id.ic_option_d);
Questions q0 = new Questions();
q0.setQuestion("Feeling Nervous ");
q0.setSelected_answer("");
questionlist.add(q0);
Questions q1= new Questions();
q1.setQuestion("Anixious,or on edge");
q1.setSelected_answer("");
questionlist.add(q1);
Questions q2= new Questions();
q2.setQuestion("Not being able to stop or control worrying");
q2.setSelected_answer("");
questionlist.add(q2);
Questions q3 = new Questions();
q3 .setQuestion("Worry to much about differnt things ?");
q3 .setSelected_answer("");
questionlist.add(q3 );
Questions q4= new Questions();
q4.setQuestion("Troble relaxing");
q4.setSelected_answer("");
questionlist.add(q4);
Questions q5= new Questions();
q5.setQuestion("Being so restless that it's hard to set still");
q5.setSelected_answer("");
questionlist.add(q5);
Questions q6= new Questions();
q6.setQuestion("Becoming easily annyed or irritable");
q6.setSelected_answer("");
questionlist.add(q6);
final TextView t= view.findViewById(R.id.question);
t.setText(questionlist.get(CURRENT_POSTION).getQuestion());
RelativeLayout rOptionA=(RelativeLayout) view.findViewById(R.id.rel_option_a);
RelativeLayout rOptionB=(RelativeLayout) view.findViewById(R.id.rel_option_b);
RelativeLayout rOptionC=(RelativeLayout) view.findViewById(R.id.rel_option_c);
RelativeLayout rOptionD=(RelativeLayout) view.findViewById(R.id.rel_option_d);
rOptionA.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// Interpret MotionEvent data
// Handle touch here
questionlist.get(CURRENT_POSTION).setSelected_answer("A");
iconA.setImageResource(R.drawable.ic_success);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_dot);
return false;
}
});
rOptionB.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// Interpret MotionEvent data
// Handle touch heresuper.onTouchEvent(event);
questionlist.get(CURRENT_POSTION).setSelected_answer("B");
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_success);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_dot);
return true;
}
});
rOptionC.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// Interpret MotionEvent data
// Handle touch here
questionlist.get(CURRENT_POSTION).setSelected_answer("C");
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_success);
iconD.setImageResource(R.drawable.ic_dot);
return true;
}
});
rOptionD.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
questionlist.get(CURRENT_POSTION).setSelected_answer("D");
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_success);
return true;
}
});
ConstraintLayout cl= view.findViewById(R.id.constraintLayout);
cl.setOnTouchListener(new OnSwipeTouchListener(getActivity()) {
#Override
public void onSwipeDown() {
}
#Override
public void onSwipeLeft() {
if(CURRENT_POSTION < FINAL_POSITION) {
CURRENT_POSTION = CURRENT_POSTION + 1;
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_dot);
Log.i("ggg", String.valueOf(CURRENT_POSTION));
question = view.findViewById(R.id.question);
question.setText(questionlist.get(CURRENT_POSTION).getQuestion());
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("")){
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_dot);
}
else{
Log.d("ELSE",( questionlist.get(CURRENT_POSTION).getSelected_answer()).toString());
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("A")){
iconA.setImageResource(R.drawable.ic_success);
}
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("B")){
iconB.setImageResource(R.drawable.ic_success);
} if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("C")){
iconC.setImageResource(R.drawable.ic_success);
}
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("D")){
iconD.setImageResource(R.drawable.ic_success);
}
}
SlideAnimationUtil.slideInFromRight(getContext(),llQuestion);
} else{
}
}
#Override
public void onSwipeUp() {
}
#Override
public void onSwipeRight() {
if(CURRENT_POSTION >START_POSITION) {
CURRENT_POSTION = CURRENT_POSTION -1;
Log.i("ggg", String.valueOf(CURRENT_POSTION));
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_dot);
TextView t = view.findViewById(R.id.question);
t.setText(questionlist.get(CURRENT_POSTION).getQuestion());
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("")){
iconA.setImageResource(R.drawable.ic_dot);
iconB.setImageResource(R.drawable.ic_dot);
iconC.setImageResource(R.drawable.ic_dot);
iconD.setImageResource(R.drawable.ic_dot);
}
else{
Log.d("ELSE",( questionlist.get(CURRENT_POSTION).getSelected_answer()).toString());
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("A")){
iconA.setImageResource(R.drawable.ic_success);
}
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("B")){
iconB.setImageResource(R.drawable.ic_success);
} if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("C")){
iconC.setImageResource(R.drawable.ic_success);
}
if((questionlist.get(CURRENT_POSTION).getSelected_answer()).equals("D")){
iconD.setImageResource(R.drawable.ic_success);
}
}
SlideAnimationUtil.slideInFromLeft(getContext(),llQuestion);
}
}
});
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
// mListener.onFragmentInteraction(uri);
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
#Override
public void onDetach() {
super.onDetach();
CURRENT_POSTION=0;
mListener = null;
}
}
My xml code
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
android:src="#drawable/three"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0" />
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginRight="0dp"
android:background="#d4ffffff"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<android.support.constraint.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.25"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="152dp" />
<TextView
android:id="#+id/question"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="35sp"
app:layout_constraintBottom_toTopOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.25" />
<RelativeLayout
android:id="#+id/rel_option_a"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/edge_rounded_border"
android:clickable="true"
android:padding="#dimen/option_relative_padding"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline4">
<ImageView
android:id="#+id/ic_option_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:tag="im_optA"
app:srcCompat="#drawable/ic_dot" />
<TextView
android:id="#+id/option_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/ic_option_a"
android:text="#string/option_a"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="17sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_option_b"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="14dp"
android:background="#drawable/edge_rounded_border"
android:padding="#dimen/option_relative_padding"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rel_option_a">
<TextView
android:id="#+id/option_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/ic_option_b"
android:text="#string/option_b"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="17sp" />
<ImageView
android:id="#+id/ic_option_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:tag="im_optB"
app:srcCompat="#drawable/ic_dot" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_option_c"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="14dp"
android:background="#drawable/edge_rounded_border"
android:padding="#dimen/option_relative_padding"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rel_option_b">
<ImageView
android:id="#+id/ic_option_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:tag="im_optC"
app:srcCompat="#drawable/ic_dot" />
<TextView
android:id="#+id/option_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/ic_option_c"
android:background="#drawable/edge_rounded"
android:text="#string/option_c"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="17sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_option_d"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="#drawable/edge_rounded_border"
android:padding="#dimen/option_relative_padding"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rel_option_c">
<ImageView
android:id="#+id/ic_option_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:tag="im_optD"
app:srcCompat="#drawable/ic_dot" />
<TextView
android:id="#+id/option_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/ic_option_d"
android:background="#drawable/edge_rounded"
android:text="#string/option_d"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="17sp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Above is my full code of fragment.I need to swipe without selecting the layer.how can I code.this image show the selection of particular layer,I am not able to swipe over this layer without selection.
my first question so I hope I'm doing this right.
I have added tablet layouts to my Android project and now I have a few crash reports on various devices. It works 100% just fine for me, however, testers with tablets get force closed at runtime.
The app is a simple dashboard allowing users to apply themes to third party launchers, Much like the Stark and Flatro icon packs.
Here's the errors:
java.lang.NoClassDefFoundError: com.arandompackage.jive.Fragment1$1
at com.arandompackage.jive.Fragment1.onActivityCreated(Fragment1.java:57)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1468)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1064)
at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432)
at android.view.View.measure(View.java:12911)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
at android.view.View.measure(View.java:12911)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
at android.view.View.measure(View.java:12911)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
at android.view.View.measure(View.java:12911)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2097)
at android.view.View.measure(View.java:12911)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
And
java.lang.RuntimeException: Unable to instantiate receiver com.arandompackage.jive.AnalogClockWidget: java.lang.ClassNotFoundException: com.arandompackage.jive.AnalogClockWidget
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2261)
at android.app.ActivityThread.access$1600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4946)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.arandompackage.jive.AnalogClockWidget
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2256)
... 10 more
I have done everything that all of these posts suggest, to no avail.
Here's the fragment1 java
package com.arandompackage.jive;
import com.arandompackage.jive.R;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
public class Fragment1 extends Fragment{
static final String ACTION_APPLY_ICON_THEME = "com.teslacoilsw.launcher.APPLY_ICON_THEME";
public static final String ACTION_MYTHEME = "com.gau.go.launcherex.MyThemes.mythemeaction";
public static final String ACTION_SET_THEME = "com.anddoes.launcher.SET_THEME";
static final String EXTRA_ICON_THEME_PACKAGE = "com.teslacoilsw.launcher.extra.ICON_THEME_PACKAGE";
static final String EXTRA_ICON_THEME_TYPE = "com.teslacoilsw.launcher.extra.ICON_THEME_TYPE";
public static final String EXTRA_PACKAGE_NAME = "com.anddoes.launcher.THEME_PACKAGE_NAME";
ImageButton button;
Button button2;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_1, null);
}
private boolean isAppInstalled(String uri) {
PackageManager pm = getActivity().getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
#Override
public void onActivityCreated (Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
button = (ImageButton) getActivity().findViewById(R.id.apextheme);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isAppInstalled("com.anddoes.launcher")) {
Intent intent3 = new Intent("com.anddoes.launcher.SET_THEME");
intent3.putExtra("com.anddoes.launcher.THEME_PACKAGE_NAME", getActivity().getPackageName());
startActivity(intent3);
Crouton.makeText(getActivity(), "TAP APPLY TO FINALIZE", Style.INFO, (ViewGroup) getView()).show();
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.apexnotfound);
alert.setMessage(R.string.apexmarket);
alert.setIcon(R.drawable.apex_1);
alert.setPositiveButton((R.string.yes),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=com.anddoes.launcher"));
startActivity(intent);
}
});
alert.setNegativeButton((R.string.no),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
return;
}
});
alert.show();
}
}
});
And the xml for fragment_1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f9f9f9"
android:paddingBottom="15dp" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" android:scrollbars="none"
android:overScrollMode="never">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<!-- Action -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="40dp" >
<ImageButton
android:id="#+id/actiontheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/alp_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/actiontheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/action"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/actiondetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/apextheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/apex_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/apextheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/apex"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/apexdetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_apex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- Nova -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/novatheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/nova_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/novatheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/nova"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/novadetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_nova"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- Adw -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:paddingTop="15dp" >
<ImageButton
android:id="#+id/adwextheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/adwex_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adwextheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/adwex"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/adwexdetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_adwex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- go -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:paddingTop="15dp" >
<ImageButton
android:id="#+id/gotheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/go_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gotheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/go"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/godetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
EDIT: Here is the FragmentAdapter.java:
package com.arandompackage.jive;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.viewpagerindicator.IconPagerAdapter;
public class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter{
protected static final String[] CONTENT = new String[] {
"This", "Is", "A", "Test"
};
private int mCount = 4;
public TestFragmentAdapter(FragmentManager fm) {
super(fm);
}
#Override
public int getIconResId(int index) {
// TODO Auto-generated method stub
return 0;
}
#Override
public Fragment getItem(int position) {
Fragment fragment = new Fragment1();
switch(position){
case 0:
fragment = new Fragment1();
break;
case 1:
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
case 3:
fragment = new Fragment4();
break;
}
return fragment;
}
#Override
public int getCount() {
return mCount;
}
#Override
public CharSequence getPageTitle(int position){
String title = "";
switch(position){
case 0:
title = "LAUNCHERS";
break;
case 1:
title = "EXTRAS";
break;
case 2:
title = "CONTACT";
break;
case 3:
title = "HELP";
break;
}
return title;
}
public void setCount(int count){
if (count > 0 && count < 10){
mCount = count;
notifyDataSetChanged();
}
}
}
And the TestFragment:
package com.arandompackage.jive;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TestFragment extends Fragment{
private static final String KEY_CONTENT = "TestFragment:Content";
public static TestFragment newInstance(String content){
TestFragment fragment = new TestFragment();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 20; i++){
builder.append(content).append(" ");
}
builder.deleteCharAt(builder.length() -1);
fragment.mContent = builder.toString();
return fragment;
}
private String mContent = "???";
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)){
mContent = savedInstanceState.getString(KEY_CONTENT);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
TextView text = new TextView(getActivity());
text.setGravity(Gravity.CENTER);
text.setText(mContent);
text.setTextSize(20 * getResources().getDisplayMetrics().density);
text.setPadding(20, 20, 20, 20);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(text);
return layout;
}
public void onSavedInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putString(KEY_CONTENT, mContent);
}
}
Here's the twist, the theme still gets applied to Apex Launcher....Any help is much appreciated in advance!
I can't remember my exact answer but this could well be to do with exporting of libraries. Go to project, properties, build path, order and export. The correct order is src, gen, android x.x.x, android private libraries, private libraries. Play around with checking/unchecking them.
I will update the answer when I get home
Edit:
My other SO answer can be found here:
Unfortunately Google Maps API Demos has stopped - Google Maps Android API v2
i am making an android app that uses the gps to mark you lat/long, speed etc but when i try to change the fields the app nolonger loads up, any ideas why? the first page to load up is MainActivity.java but this is just a logo screen that loads the app then uses
setContentView(R.layout.main_page);
to load the MainPageActivity.Java that i will be using to do most of the app stuff here is the code for that
here is the code for MainActivity.Java:
package com.aramis;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity implements Runnable {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
setContentView(R.layout.main_page);
}
}.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void run() {
// TODO Auto-generated method stub
}
public void GoToMap(View view) {
setContentView(R.layout.map);
}
public void GoToOpt(View view) {
setContentView(R.layout.options);
}
public void GoToStart(View view) {
setContentView(R.layout.main_page);
}
}
and here is the code for MainPageActivity.Java:
package com.aramis;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainPageActivity extends Activity {
/** Called when the activity is first created. */
EditText et_gpsLAT;
EditText et_gpsLONG;
ProgressDialog progressDialog;
Thread thread;
String info;
LocationManager mlocManager=null;
LocationListener mlocListener;
AlertDialog.Builder alert;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
et_gpsLAT=(EditText)findViewById(R.id.et_gpsLAT);
et_gpsLONG=(EditText)findViewById(R.id.et_gpsLONG);
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Button btn_gps=(Button)findViewById(R.id.btn_gps);
btn_gps.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
if(MyLocationListener.latitude>0 )
{
et_gpsLAT.setText("Latitude: "
+ MyLocationListener.latitude
+ '\n');
et_gpsLONG.setText("Longitude: "
+ MyLocationListener.longitude);
}
}
}
}
);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_page, menu);
return true;
}
}
and here is a copy of the page that will display the lat/long:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/backrepeat"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="#string/LatENG"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:text="#string/Long"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:text="#string/Alt"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="20dp"
android:text="#string/Speed"
tools:context=".MainActivity" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_marginRight="21dp"
android:text="#string/Current_Lat"
tools:context=".MainActivity" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignRight="#+id/TextView02"
android:text="#string/Current_Long"
tools:context=".MainActivity" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/TextView01"
android:text="#string/Current_Alt"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignRight="#+id/TextView03"
android:text="#string/Current_Speed"
tools:context=".MainActivity" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="GoToMap"
android:text="#string/mapbtn" />
<Button
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="GoToOpt"
android:text="#string/optbtn" />
<Button
android:id="#+id/btn_gps"
style="#style/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="33dp"
android:text=" GPS " />
<EditText
android:id="#+id/et_gpsLAT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_gps"
android:layout_centerHorizontal="true"
android:editable="false"
android:ems="10" />
<EditText
android:id="#+id/et_gpsLONG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_gpsLAT"
android:layout_below="#+id/et_gpsLAT"
android:editable="false"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/tv_gps"
style="#style/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btn_gps"
android:layout_alignParentLeft="true"
android:text="Location :" />
</RelativeLayout>
any help with this would be apreciated i have been stuck on this for a while now