This is my code for MainActivity.java
Here I am creating a very basic LoginApp. When the App runs, it gives "unfortunately stopped working ERROR..."
package com.example.loginapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
EditText t1,t2;
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1= (Button) b1.findViewById(R.id.button1);
t1=(EditText) t1.findViewById(R.id.editText1);
t2=(EditText) t2.findViewById(R.id.editText2);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View arg0)
{
//String user;
//user = t1.setText("user");
if (arg0.findViewById(R.id.button1)==b1)
{
if ((boolean)((t1.getText().toString()=="user")) && (t2.getText().toString()=="user"))
{
Toast.makeText(this, "Login Sucessful", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Sorry", Toast.LENGTH_SHORT).show();
t1.setText("");
t2.setText("");
}
}
}
}
Following is code for activity_main.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:gravity="center"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/editText1"
android:text="Username"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_centerVertical="true"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="115dp"
android:layout_marginTop="22dp"
android:ems="10" >
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignLeft="#+id/editText1"
android:ems="10"
android:inputType="numberPassword" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="46dp"
android:layout_toRightOf="#+id/textView2"
android:clickable="true"
android:onClick="onClick"
android:text="Login" />
</RelativeLayout>
Code for AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.loginapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hi please repleace the onCreate method as
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1= (Button) findViewById(R.id.button1);
t1=(EditText) findViewById(R.id.editText1);
t2=(EditText) findViewById(R.id.editText2);
}
It will helpful for you.
After modified the code it working fine for me.Please try and let me know.
Related
I want to make that people visit my website one time one site per person.
i am using mysql database for my data base .
i want to make when the user click on the visit button the he will redirect to the site (i had configured).
and that persion not able to go same site again. the button should show visited and its should be disable or hide form recyclar view (How to do,I want this).
My adapter class:
public class MyAdapter extends RecyclerView.Adapter<ImageViewHOlder> {
private Context context;
private List<ModelImage> imageList;
public MyAdapter(Context context, List<ModelImage> imageList) {
this.context = context;
this.imageList = imageList;
}
#NonNull
#Override
public ImageViewHOlder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_layout_item,parent,false);
return new ImageViewHOlder(view);
}
#Override
public void onBindViewHolder(#NonNull ImageViewHOlder holder, final int position) {
holder.title.setText(imageList.get(position).getPost_title());
holder.date.setText("Uploaded on: "+imageList.get(position).getDate());
Glide.with(context).load(imageList.get(position).getFeatured_image()).into(holder.imageView);
holder.check.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String url = imageList.get(position).getPost_slug();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
context.startActivity(i);
}
});
}
#Override
public int getItemCount() {
return imageList.size();
}
}
class ImageViewHOlder extends RecyclerView.ViewHolder{
ImageView imageView;
TextView title,date;
Button check;
public ImageViewHOlder(#NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.imageView);
title = itemView.findViewById(R.id.title);
date = itemView.findViewById(R.id.date);
check = itemView.findViewById(R.id.check);
}
}
my custom layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardCornerRadius="15dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="25dp"
android:layout_marginEnd="5dp"
android:background="#color/colorPrimaryDark"
android:text="Visit"
android:textColor="#000"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView"
android:padding="5dp"
android:layout_marginTop="7dp"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/date"
android:layout_marginEnd="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/check"
android:layout_alignParentEnd="true"
android:layout_marginStart="15dp"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_marginStart="15dp"
android:layout_toEndOf="#+id/imageView"
android:layout_toStartOf="#+id/check"
android:singleLine="true"
android:textSize="20sp" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_toEndOf="#+id/imageView"
android:singleLine="true"
android:textSize="20sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
Alas! after a lots of efforts and search I couldn't find my problem. I want to find current location in google map but I am still getting an error(required permissions).
call requires permission which may be rejected by user: code should
explicitly check to see if permission is available (with check
permission) or explicitly handle a potential 'security Exception'
at gMap.setMyLocationEnable(true); Please anybody guide me how can I fix it? My code is given below.
AddMasjid.java
package com.example.saroosh.masjidnow.Tabs;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.saroosh.masjidnow.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class AddMasjid extends Fragment implements OnMapReadyCallback{
MapView gMapView;
GoogleMap gMap = null;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.add_masjid,container,false);
gMapView = (MapView) v.findViewById(R.id.map);
gMapView.getMapAsync(this);
gMapView.onCreate(savedInstanceState);
gMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
return v;
}
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(0, 0), 0));
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
gMap.setMyLocationEnabled();
}
}
#Override
public void onResume() {
super.onResume();
gMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
gMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
gMapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
gMapView.onLowMemory();
}
}
add_masjid.xml
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
android:background="#000000">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentStart="true"
android:text="#string/xyz"
android:textColor="#FFFFFF"
android:textSize="20sp"
/>
<Button
android:id="#+id/generalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="#drawable/rect1"
android:onClick="geoLocate"
android:text="#string/abc"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/textView1"
android:layout_toStartOf="#+id/generalId"
android:ems="10"
android:inputType="text"
android:background="#FFFFFF"
android:labelFor="#+id/editText1"
android:layout_above="#+id/map"
android:layout_alignParentTop="true" />
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/generalId">
</com.google.android.gms.maps.MapView>
</RelativeLayout>
I have just solved my problem by adding some permissions in it.
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(0, 0), 0));
//add this code...
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext()
, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext()
, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
gMap.setMyLocationEnabled(true);
gMap.getUiSettings().setMyLocationButtonEnabled(true);
}
}
I try to bind the selected item of a MvxListView to my property. This is my Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="#layout/toolbar_actionbar" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:paddingRight="6dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_search_text"
local:MvxBind="Text SearchText" />
<MvxListView
android:id="#+id/category_list"
android:orientation="vertical"
android:choiceMode="singleChoice"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxItemTemplate="#layout/listitem_category"
local:MvxBind="ItemsSource Categories; SelectedItem SelectedCategory" />
</LinearLayout>
</LinearLayout>
The ItemSource here is properly bound.
ViewModel:
[ImplementPropertyChanged]
public class SelectCategoryListViewModel : AbstractCategoryListViewModel
{
/// <summary>
/// Creates an CategoryListViewModel for the usage of providing a category selection.
/// </summary>
/// <param name="categoryRepository">An instance of <see cref="IRepository{T}" /> of type category.</param>
/// <param name="dialogService">An instance of <see cref="IDialogService" /></param>
public SelectCategoryListViewModel(IRepository<Category> categoryRepository,
IDialogService dialogService) : base(categoryRepository, dialogService)
{}
public Category SelectedCategory { get; set; }
public MvxCommand DoneCommand => new MvxCommand(Done);
public MvxCommand CancelCommand => new MvxCommand(Cancel);
private void Done()
{
MessageHub.Publish(new CategorySelectedMessage(this, SelectedCategory));
Close(this);
}
private void Cancel()
{
Close(this);
}
}
Not the notify PropertyChanged is done via Fody and Categories are in the parent VM.
public class SelectCategoryListActivity : MvxFragmentCompatActivity<SelectCategoryListViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.fragment_category_list);
SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.toolbar));
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
}
...
The Warning I get is:
[0:] MvxBind:Warning: 5.11 Failed to create target binding for binding SelectedItem for SelectedCategory
Ideas?
I just came across a similar issue with a SelectedItem binding failing. The solve was to update Mvx to version 4.1.6. The reason being is that you need to register MvxAppCompatSetupHelper.FillTargetFactories, with 4.1.6 this is now done automatically.
Alternatively, you can manually register it in you setup.cs by overriding FillTargetFactories:
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
MvxAppCompatSetupHelper.FillTargetFactories(registry);
base.FillTargetFactories(registry);
}
I'm building an air extension and the very first method to call on my extention is to check if
GCMRegistrar.checkDevice($context.getActivity());
GCMRegistrar.checkManifest($context.getActivity());
are supported and set, so wrote: CheckGcm.java
package com.doitflash.air.extensions.gcm;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;
import com.google.android.gcm.GCMConstants;
import com.google.android.gcm.GCMRegistrar;
public class CheckGcm implements FREFunction
{
private String _result;
public FREObject call(FREContext $context, FREObject[] $params)
{
//$context.dispatchStatusEventAsync("variable", "value");
try
{
GCMRegistrar.checkDevice($context.getActivity());
GCMRegistrar.checkManifest($context.getActivity());
_result = "true";
}
catch(Exception err)
{
_result = "false";
}
return as3ConvertValue(_result);
}
private FREObject as3ConvertValue(String $value)
{
try
{
return FREObject.newObject($value);
}
catch (FREWrongThreadException e)
{
return null;
}
}
}
and I setup the android manifest like this:
<manifestAdditions><![CDATA[<manifest android:installLocation="auto">
<permission android:name="air.air.com.doitflash.SampleApp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="air.air.com.doitflash.SampleApp.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application>
<activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:enabled="true"
android:exported="true"
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="air.air.com.doitflash.SampleApp" />
</intent-filter>
</receiver>
<service
android:enabled="true"
android:exported="true"
android:name="com.doitflash.air.extensions.gcm.GCMIntentService" />
</application>
</manifest>]]></manifestAdditions>
I have also setup GCMIntentService:
package com.doitflash.air.extensions.gcm;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService
{
private static final String TAG = "===GCMIntentService===";
public GCMIntentService()
{
super("000000"); // senderID
}
#Override
protected void onRegistered(Context arg0, String registrationId)
{
}
#Override
protected void onUnregistered(Context arg0, String arg1)
{
}
#Override
protected void onMessage(Context arg0, Intent arg1)
{
//Log.i(TAG, "notification title = " + arg1.getStringExtra("title"));
//Log.i(TAG, "notification message = " + arg1.getStringExtra("msg"));
//Log.i(TAG, "notification type = " + arg1.getStringExtra("type"));
//Log.i(TAG, "notification id= " + arg1.getStringExtra("id"));
}
#Override
protected void onError(Context arg0, String errorId)
{
}
#Override
protected boolean onRecoverableError(Context context, String errorId)
{
return super.onRecoverableError(context, errorId);
}
}
everything looks fine in my eyes but when I try tracing the check method in my air project, it returns null! so I know there must be something wrong with:
GCMRegistrar.checkDevice($context.getActivity());
GCMRegistrar.checkManifest($context.getActivity());
because when I remove these two lines, the trace in air returns true. just before starting to build the air extension, I built a sample GCM in java and everything was working perfectly but I don't seem to understand why the air version does not work. any ideas?
UPDATE: I used eclipse logcat to see what is happening on my phone and this may be some hints:
Could not find method com.google.android.gcm.GCMRegistrar.checkDevice, referenced from method com.doitflash.air.extensions.gcm.CheckGcm.call
unable to resolve static method 284: Lcom/google/android/gcm/GCMRegistrar;.checkDevice (Landroid/content/Context;)V
I have an Android app that uses tabs for its start menu. The tabs don't display when I port the app to a Kindle Fire. Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:isScrollContainer="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/Beginning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/Intermediate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/Advanced"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</ScrollView>
package com.myproject.project;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;
public class TabsTestActivity extends Activity {
/** Called when the activity is first created. */
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_LEVEL = "level";
public static final String KEY_CHART = "charted";
public String extStorageDirectory = Environment
.getExternalStorageDirectory().toString();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PopulateDatabase();
CopyVideoFiles();
TabHost tabhost = (TabHost) findViewById(R.id.tabhost);
tabhost.setup();
TabSpec spec_beg = tabhost.newTabSpec("Beginning");
spec_beg.setContent(R.id.Beginning);
TextView txtTabInfo = new TextView(this);
txtTabInfo.setText("JUST STARTING");
Typeface font = Typeface.createFromAsset(getAssets(), "danielbd.ttf");
txtTabInfo.setTypeface(font);
txtTabInfo.setGravity(Gravity.CENTER);
txtTabInfo.setHeight(50);
txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
txtTabInfo.setTextColor(Color.parseColor("#262405"));
spec_beg.setIndicator(txtTabInfo);
TabSpec spec_int = tabhost.newTabSpec("Intermediate");
spec_int.setContent(R.id.Intermediate);
txtTabInfo = new TextView(this);
txtTabInfo.setText("GETTING THERE");
txtTabInfo.setTypeface(font);
txtTabInfo.setGravity(Gravity.CENTER);
txtTabInfo.setHeight(50);
txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
txtTabInfo.setTextColor(Color.parseColor("#262405"));
spec_int.setIndicator(txtTabInfo);
TabSpec spec_adv = tabhost.newTabSpec("Advanced");
spec_adv.setContent(R.id.Advanced);
txtTabInfo = new TextView(this);
txtTabInfo.setText("REALLY GOOD");
txtTabInfo.setTypeface(font);
txtTabInfo.setGravity(Gravity.CENTER);
txtTabInfo.setHeight(50);
txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
txtTabInfo.setTextColor(Color.parseColor("#262405"));
spec_adv.setIndicator(txtTabInfo);
// get data from database, create buttons and name them
SQLData myTable = new SQLData(this);
myTable.open();
Cursor c = myTable.getallData();
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int iLevel = c.getColumnIndex(KEY_LEVEL);
// create the buttons
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
final String RowNum = c.getString(iRow);
String Name = c.getString(iName);
final String Level = c.getString(iLevel);
Button button = new Button(this);
button.setText(Name);
button.setHeight(20);
button.setTextColor(Color.BLACK);
button.setBackgroundColor(Color.parseColor("#A89E0A"));
button.setHighlightColor(Color.WHITE);
button.setTypeface(font);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent choice = new Intent(getApplicationContext
(),
com.myproject.project.myclass.class);
Bundle dataBundle = new Bundle();
dataBundle.putString("RowID", RowNum);
dataBundle.putString("Level", Level);
choice.putExtras(dataBundle);
try {
startActivity(choice);
} catch (Exception e) {
Dialog d = new Dialog(getApplicationContext());
d.setTitle("TabsTestActivity line 131");
TextView tv = new TextView(getApplicationContext());
tv.setText(e.toString());
d.setContentView(tv);
d.show();
} finally {
}
}
});
LinearLayout lbeg = (LinearLayout) findViewById(R.id.Beginning);
LinearLayout lint = (LinearLayout) findViewById(R.id.Intermediate);
LinearLayout ladv = (LinearLayout) findViewById(R.id.Advanced);
if (Level.equals("Beginning"))
lbeg.addView(button);
else if (Level.equals("Intermediate"))
lint.addView(button);
else if (Level.equals("Advanced"))
ladv.addView(button);
}
tabhost.addTab(spec_beg);
tabhost.addTab(spec_int);
tabhost.addTab(spec_adv);
myTable.close();
}}
Does anyone know why? The tabs and their contents show up fine in the emulator and on my Android phone. Thanks!
I have since learned that the Kindle Fire does not support Tabs