aspose file tools*
The moose likes Android and the fly likes problem in pattern matching android Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "problem in pattern matching android" Watch "problem in pattern matching android" New topic
Author

problem in pattern matching android

deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
hi,

i have written an code for pattern matching in android. there is no compilation or run time error. i have a string like this " hi how are you" and if it matches it should display the same output. but i am not getting the result alone. can any one tell where i have missed some statement it would be of great help indeed.

code is
package com.example.android.pattern;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class PatternActivity extends Activity {
TextView tt;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
{
String raw_string = ("hi how are you");
Pattern p = Pattern.compile("hi how are you");
Matcher m = p.matcher(raw_string);
if (m.find()){
String res = m.toMatchResult().group(0);
tt = setText(res.toString());
}

}
private TextView setText(String res) {
// TODO Auto-generated method stub
return null;
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<Button android:layout_width="wrap_content"
android:id="@+id/calculate"
android:layout_x="41dip"
android:layout_height="wrap_content"
android:text="Calculate"
android:layout_y="232dip"></Button>

<EditText android:text=""
android:layout_width="wrap_content"
android:layout_x="172dip"
android:id="@+id/tt"
android:layout_height="wrap_content"
android:layout_y="232dip"></EditText>

</LinearLayout>

can any one tell what is the error. i have attached the emulator link here


[Thumbnail for output-for-pattern-matching-javaranch.png]

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Which statement, exactly, do you think should cause something to be displayed?
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
the statement " String res = m.toMatchResult().group(0);"

and tt is for viewing the text that is matched so i have given an statement like this
tt = setText(res.toString());

is my declaration wrong for displaying the output ?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Let me put it another way: there is nothing in your code that would cause anything to be displayed. The setText method should change the text that is displayed by the TextView; check the javadocs of that class for how the method is called. Currently that method does nothing. And you should definitely not reassign "tt" to null (or anything else after it's been initialized - which, actually, it isn't anywhere. You should do that in the onCreate method.)
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
i am unable to find out what your telling in the code and where to put in in the code. can you please help me to get the output? is the html tag is correct?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
That's not HTML, it's XML. I suggest you work through an introductory tutorial on how to build GUIs on Android; they cover stuff like this. As long as the code doesn't obtain a proper reference to "tt", and then calls an appropriate method on it to make it display whatever text you want it to display, nothing will be displayed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in pattern matching android
 
Similar Threads
Layouts, bottom position
display in output is not seen for addition program
Why error in this code
How to retrieve string from EditText?
nullpointer when i try to initiate onclicklistener